Created
October 29, 2019 16:17
-
-
Save lgedeon/700a869f494a97934a14e23360202ab0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
/** | |
* Create a multidimensional array from supplied array keys. | |
* | |
* Accepts a variable number of parameters that can be strings or arrays of | |
* strings. Each parameter represents another level of nesting. | |
* | |
* Each leaf node is an empty array. | |
* | |
* @param mixed $args,... Variable number of strings or arrays of strings. | |
* | |
* @return array | |
*/ | |
public function nest_array_keys( ...$args ) { | |
$keys = (array) array_shift( $args ); | |
$array = []; | |
foreach ( $keys as $key ) { | |
$array[ $key ] = call_user_func_array( [ $this, __FUNCTION__ ], $args ); | |
} | |
return $array; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment