gpt4 book ai didi

php - array_shift 来自数组中的数组

转载 作者:可可西里 更新时间:2023-10-31 22:13:12 26 4
gpt4 key购买 nike

我正在尝试删除最后一个数组的第一个元素

数组:

$harbours = array(
'67' => array('boat1', 'boat2'),
'43' => array('boat3', 'boat4')
);

我想删除并返回 boat3

$last = end($harbours);
$boat = array_shift($last);

如果我然后 print_r ($harbours),'boat3' 仍然存在。

最佳答案

那是因为在 array_shift 中,您正在更改结束数组的副本

您需要获取结束数组的引用才能移动它。

试试这个:

end($array);

$currKey = key($array); //get the last key

array_shift($array[$currKey]);

参见演示:http://codepad.org/ey3IVfIL

关于php - array_shift 来自数组中的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13953706/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com