Skip to content

Instantly share code, notes, and snippets.

@FirePanther
Last active November 17, 2016 04:06
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 FirePanther/3f3152ee25ab9b34af5f to your computer and use it in GitHub Desktop.
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
<?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