Skip to content

Instantly share code, notes, and snippets.

@matesnippets
Created October 10, 2016 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matesnippets/f9c439aa82d4d13e350d71fa7785f6ae to your computer and use it in GitHub Desktop.
Save matesnippets/f9c439aa82d4d13e350d71fa7785f6ae to your computer and use it in GitHub Desktop.
A recursive function to parse a multidimensional array from a string
/**
* 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