我试图删除最后一个数组的第一个元素
数组:
$harbours = array(
'67' => array('boat1', 'boat2'),
'43' => array('boat3', 'boat4')
);
Run Code Online (Sandbox Code Playgroud)
我想删除并返回 boat3
$last = end($harbours);
$boat = array_shift($last);
Run Code Online (Sandbox Code Playgroud)
如果我那么print_r ($harbours),'boat3'仍在那里.
Nea*_*eal 10
那是因为array_shift您正在更改结束数组的副本.
您需要获取结束数组的引用才能移动它.
试试这个:
end($array);
$currKey = key($array); //get the last key
array_shift($array[$currKey]);
Run Code Online (Sandbox Code Playgroud)
请参阅演示:http://codepad.org/ey3IVfIL