Remove first result in array
This question already has an answer here:
To remove an element from an array,
unset($dataArray[0]);
Note that the other element indexes are the same.
或者,您可以使用array_shift,这也会重置数组上的索引,而未unset
则不会。
$unsetTest = array('hey','now','brown','cow');
$shiftTest = array('hey','now','brown','cow');
unset($unsetTest[0]);
array_shift($shiftTest);
var_dump($unsetTest);
var_dump($shiftTest);
//output
array(3) {
[1]=>
string(3) "now"
[2]=>
string(5) "brown"
[3]=>
string(3) "cow"
}
array(3) {
[0]=>
string(3) "now"
[1]=>
string(5) "brown"
[2]=>
string(3) "cow"
}
链接地址: http://www.djcxy.com/p/30116.html
上一篇: PHP:删除第4项中的第三项逗号列表“1,2,3,4”
下一篇: 删除数组中的第一个结果