gpt4 book ai didi

php - 如何使用 array_push 向数组添加值和键

转载 作者:行者123 更新时间:2023-12-03 23:03:49 26 4
gpt4 key购买 nike

此代码运行后我收到错误消息。我查找了可能的解决方案,但所有内容的格式似乎都正确。

$searched = 'searched';    
$count = '59';
$prop = Array();

$i = 0;
while ($i++ <= 4) {
array_push($prop[$i] = Array(
'text' => $searched,
'href' => 'http://mysite.com/?search=' . str_replace(' ', '+', $searched)
));
}

array_push($prop['Total Searches'] = $count);

我在 while 循环中收到此错误 5 次,在 while 循环下的 array_push 中收到此错误 1 ​​次。

Warning: Wrong parameter count for array_push()

代码运行正常!但它仍然会报错。那么我应该只抑制错误吗?

最佳答案

改变:

array_push($prop['Total Searches'] = $count);

到:

$prop['Total Searches'] = $count;

等等

您仅使用 array_push 将值推送到列表样式数组的末尾。这与这里无关,因为您只是设置一个新的键/值对。

关于php - 如何使用 array_push 向数组添加值和键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6103444/

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