Created
December 26, 2019 14:54
-
-
Save zmf/11eeae4ee02030ad4b406b922ca4db6a to your computer and use it in GitHub Desktop.
vertical_to_horizontal_array.php
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 | |
$flat = [ 'this', 'seems', 'a', 'bit', 'strange']; | |
$nested = []; | |
function v2h_array(&$flat, &$nested) { | |
$nested[$flat[0]] = []; | |
while (count($flat) > 1) { | |
v2h_array(array_splice($flat, 1, count($flat)-1), $nested[$flat[0]]); | |
} | |
return false; | |
} | |
v2h_array($flat, $nested); | |
var_dump($nested); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment