gpt4 book ai didi

PHP array_shift() 对我不起作用。我究竟做错了什么?

转载 作者:行者123 更新时间:2023-12-01 08:17:41 26 4
gpt4 key购买 nike

我正在创建一个数组并想删除数组的第一个元素并重新索引它。据我所知, array_shift() 是正确的解决方案。但是,它在我的实现中不起作用。

我有一个类的成员变量,它被定义为一个名为 $waypoint_city 的数组。这是移动数组之前的变量输出:

print_r($this->waypoint_city);

结果:
Array ( [0] => [1] => JACKSONVILLE [2] => ORLANDO [3] => MONTGOMERY [4] => MEMPHIS )

如果我执行以下操作,我会得到正确的结果:
print_r(array_shift($this->waypoint_city));

结果:
Array ( [0] => JACKSONVILLE [1] => ORLANDO [2] => MONTGOMERY [3] => MEMPHIS )

但是,如果我尝试将结果重新分配给成员变量它不起作用......有人知道这是为什么吗?
$this->waypoint_city = array_shift($this->waypoint_city);

如果我尝试 print_r($this->waypoint_city) ,它看起来好像什么都没有。感谢任何能拯救我还没有拔掉的头发的人。

最佳答案

array_shift [docs]更改数组 就地 .它返回第一个元素(在您的情况下为空):

Returns the shifted value, or NULL if array is empty or is not an array.



您所要做的就是:
array_shift($this->waypoint_city);

关于PHP array_shift() 对我不起作用。我究竟做错了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6541919/

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