Last active
February 28, 2021 16:57
-
-
Save felipsmartins/b8a5a8f7a8547506c5a7 to your computer and use it in GitHub Desktop.
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 | |
# StackOverflow related question: http://stackoverflow.com/questions/34886008/create-nested-array-by-array-of-key | |
# The @Gavriel's answer is pretty good! | |
# But it could be somewhat more "*easy to catch*" like this: | |
$new = $value; | |
foreach (array_reverse($keys) as $valueAsKey) $new = [$valueAsKey => $new]; | |
# In fact, it's a version of @Gavbriel's answer using array_reverse() and some semantic variables. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment