Created
October 10, 2016 15:08
-
-
Save matesnippets/f9c439aa82d4d13e350d71fa7785f6ae to your computer and use it in GitHub Desktop.
A recursive function to parse a multidimensional array from a string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A recursive function to parse a multidimensional array from a string | |
* | |
* @param array $delimiter Array of delimiters | |
* @param string $string The string to parse | |
* @return array Multidimensional array | |
*/ | |
function n26_multi_explode(array $delimiter, $string) { | |
// Shift the array | |
$d = array_shift($delimiter); | |
if ($d != null) { | |
// Filter the array to make sure we don't create empty nodes | |
$tmp = array_filter(explode($d, $string), 'strlen'); | |
foreach ($tmp as $key => $o) { | |
$out[$key] = n26_multi_explode($delimiter, $o); | |
} | |
} else { | |
return $string; | |
} | |
return $out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment