$input = "hello|world|look|at|this";
$explode = explode("|", $input);
$array = array("Title" => "Hello!", "content" => $explode);
这将输出:
array(2) {
["Title"]=>
string(6) "Hello!"
["content"]=>
array(5) {
[0]=>
string(5) "hello"
[1]=>
string(5) "world"
[2]=>
string(4) "look"
[3]=>
string(2) "at"
[4]=>
string(4) "this"
}
}
但我希望它们是带有 NULL 作为值的键,因为我会在后面的步骤中添加值。
知道如何让 explode()
函数作为键返回吗? php 有函数吗可用吗?
最佳答案
array_fill_keys
可以基于数组填充键:
array_fill_keys ($explode, null);
关于php - 将 explode 数组作为键添加到新数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21133333/