Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
$array = array('a', 'b','c'); unset($array[0]); var_dump($array); Yields: array(1) { [1]=> 'b' 'c' }
我如何删除 array[0] 以获取 ['bb','cc'] (没有空键):
array(1) { 'b' 'c' }
检查这个:
$array = array('a', 'b','c'); unset($array[0]); $array = array_values($array); //reindexing
看一眼array_splice()
array_splice()
$array = array_splice($array, 0, 1);
如果您碰巧专门删除了第一个元素(而不是数组中间的任意元素),array_shift()则更合适。
array_shift()