2011-11-17 39 views
0
$allAmazonMatches = Array ([1] => B002I0HJZO [2] => B002I0HJzz [3] => B002I0HJccccccccc) 

我做:我的数组追加函数有什么问题?

array_push($allAmazonMatches, array("0"=>"None of the products match")); 

如何过,我无法将其它阵列添加到$ allAmazonMatches?

+0

你是什么意思的“添加额外的数组”? – Arfeen

回答

1

该代码将正常工作,因此IM假设youre设法输入文本到数组的索引0。你应该做...

$allAmazonMatches[0] = "None of the products match"; 
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")); 
+0

我做到了,但没有发生任何事 – jini

+0

你期望什么,发生了什么? – AndreKR

+0

阵列( [1] => B002I0HJZO [2] => B002I0HJzz [3] => B002I0HJccccccccc [4] =>数组( [0] =>产品的无匹配 ) ) – jini

1

您不需要仅使用一个元素的数组推送。这里就是你要找做什么,有三个变化沿demo

$allAmazonMatches = array(1 => "B002I0HJZO", 2 => "B002I0HJzz", 3 => "B002I0HJccccccccc"); 
$allAmazonMatches[] = "None of the products match"; 
var_dump($allAmazonMatches);