Skip to content

Instantly share code, notes, and snippets.

@lgedeon
Created October 29, 2019 16:17
Show Gist options
  • Save lgedeon/700a869f494a97934a14e23360202ab0 to your computer and use it in GitHub Desktop.
Save lgedeon/700a869f494a97934a14e23360202ab0 to your computer and use it in GitHub Desktop.
<?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