我有一个要分解成数组的字符串,并且众所周知,输出数组键将从第一个元素的键开始于0,第二个元素从1开始,依此类推。
现在如何强制该数组从1开始而不是0?
对于类型化数组,这非常简单,因为我们可以这样写:
array('1'=>'value', 'another value', 'and another one');
但是使用爆炸动态创建的数组,该怎么做?
谢谢。
最佳答案
$exploded = explode('.', 'a.string.to.explode');
$exploded = array_combine(range(1, count($exploded)), $exploded);
var_dump($exploded);
做完了!
关于php - php explode 并强制数组键从1开始而不是0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13148506/