Last active
November 17, 2016 04:06
-
-
Save FirePanther/3f3152ee25ab9b34af5f to your computer and use it in GitHub Desktop.
Parses the array, sind it up/combines it with dots, written for @bluefirex
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
<?php | |
$a = [ | |
"some" => [ | |
"thing" => [ | |
"is" => [ | |
"happening" => [ | |
50, 20, 90 | |
] | |
] | |
], | |
"awesome" => [ | |
"things" => [ | |
90, 20 | |
] | |
] | |
] | |
]; | |
print_r(parse($a)); | |
function parse($p) { | |
foreach ($p as $k => &$v) { | |
switch (count($v)) { | |
case 1: | |
if (is_array($v)) { | |
$sk = key($v); | |
unset($p[$k]); | |
$p["$k.$sk"] = $v[$sk]; | |
} | |
break; | |
default: | |
$v = parse($v); | |
} | |
} | |
return $p; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment