I have this $array
in which the index
key could appear in any random order:
我有这个$数组,索引键可以以任意的顺序出现:
array(4) {
["foo"]=> bool(false)
["index"]=> bool(false)
["bar"]=> bool(true)
["biff"]=> bool(false)
}
Without adjusting the position of the elements or changing the key or value, how do I remove the index
element, resulting in a new $array
?
在不调整元素位置或更改键或值的情况下,如何删除索引元素,从而生成一个新的$数组?
array(3) {
["foo"]=> bool(false)
["bar"]=> bool(true)
["biff"]=> bool(false)
}
3 个解决方案
#1
6
Use:
使用:
unset($array['index']);
#2
4
unset($array['index']);
#3
3
unset($array['index']);
is what you're looking for. This will work even if there is no 'index' key in the array.
设置($阵列(“指数”));这就是你想要的。即使数组中没有“索引”键,它也可以工作。
#1
6
Use:
使用:
unset($array['index']);
#2
4
unset($array['index']);
#3
3
unset($array['index']);
is what you're looking for. This will work even if there is no 'index' key in the array.
设置($阵列(“指数”));这就是你想要的。即使数组中没有“索引”键,它也可以工作。