我有一个数组,像,
Array
(
[0] => controllers
[1] => event
[2] => add_new_file.php
)
Run Code Online (Sandbox Code Playgroud)
我想改变它
Array([controllers]=>[event]=>add_new_file.php)
Run Code Online (Sandbox Code Playgroud)
是否有任何改变这样的想法,任何人都有想法改变这样的想法.
试试:
$input = array('controllers', 'event', 'add_new_file.php');
$output = null;
foreach (array_reverse($input) as $value) {
if (is_null($output)) {
$output = $value;
} else {
$output = array($value => $output);
}
}
Run Code Online (Sandbox Code Playgroud)
输出:
array (size=1)
'controllers' =>
array (size=1)
'event' => string 'add_new_file.php' (length=16)
Run Code Online (Sandbox Code Playgroud)