$allAmazonMatches = Array ( [1] => B002I0HJZO [2] => B002I0HJzz [3] => B002I0HJccccccccc )
我在做:
array_push($allAmazonMatches, array("0"=>"None of the products match"));
但是,我无法将其他数组添加到$ allAmazonMatches?
答案 0 :(得分:1)
使用array_push
即可获得:
Array(
[1] => B002I0HJZO
[2] => B002I0HJzz
[3] => B002I0HJccccccccc
[4] => Array(
[0] => None of the products match
)
)
我想,这不是你想要的,但你正在寻找:
Array(
[1] => B002I0HJZO
[2] => B002I0HJzz
[3] => B002I0HJccccccccc
[4] => None of the products match
)
然后你必须使用:
array_merge($allAmazonMatches, array("0"=>"None of the products match"));
答案 1 :(得分:1)
您不需要仅使用一个元素来使用数组推送。以下是您要做的事情,以及demo中的三个变体:
$allAmazonMatches = array( 1 => "B002I0HJZO", 2 => "B002I0HJzz", 3 => "B002I0HJccccccccc");
$allAmazonMatches[] = "None of the products match";
var_dump( $allAmazonMatches);
答案 2 :(得分:1)
该代码可以正常工作,因此我假设您尝试将该文本输入到数组的索引0
中。你应该做...
$allAmazonMatches[0] = "None of the products match";