gpt4 book ai didi

php - 格式化数组值

转载 作者:可可西里 更新时间:2023-11-01 00:21:50 24 4
gpt4 key购买 nike

我有一个像这样的数组

Array
(
[0] => controllers
[1] => event
[2] => add_new_file.php
)

我想改成这样

Array([controllers]=>[event]=>add_new_file.php)

Is any idea about to change like this,Anyone have idea to change like this.

最佳答案

尝试:

$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);
}
}

输出:

array (size=1)
'controllers' =>
array (size=1)
'event' => string 'add_new_file.php' (length=16)

关于php - 格式化数组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18719151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com