假设您有一个逗号分隔的字符串:
$str = 'a,b,c';
Calling explode(',', $str);
will return the following:
array('a', 'b', 'c')
有没有一种爆炸方法可以填充结果数组的键而不是值?像这样:
array('a' => null, 'b' => null, 'c' => null)
假设您有一个逗号分隔的字符串:
$str = 'a,b,c';
Calling explode(',', $str);
will return the following:
array('a', 'b', 'c')
有没有一种爆炸方法可以填充结果数组的键而不是值?像这样:
array('a' => null, 'b' => null, 'c' => null)
You can use
array_fill_keys
to use the output ofexplode
as keys to a new array with a given value:输出:
Demo on 3v4l.org
像这样的东西:
不是那么漂亮,但是有效