2011-03-24 60 views
0

我有一個數組:PHP添加特定值代入預先存在的陣列

$availAds[$imageFile] = array(
     'image' => $imageFile, 
     'title' => $artDetails[0], 
     'link' => $artDetails[1] 
    ); 

,我有需要被添加到陣列和分配了相同的值基於有內容的值:

 foreach($querytitle as $currentTitle ): 
    $titlearray = $currentTitle->nodeValue ; 
    array_push($availArts,$titlearray); 
    endforeach; 

我使用array_push並把它添加到陣列的罰款,但我ened能夠「標題」分配給$ currentTitle。

希望這是有道理的,和感謝。

回答

0

您應該參考php.net array documentation

簡單地說,你可以添加項目在幾個方面對數組:

$array[] = "foo";  // add "foo" to the end of array (same as array_push) 
$array[1] = "foo";  // add "foo" at array index 1 
$array['foo'] = "bar"; // add "bar" at the "foo" index of array 
0
$availArts[$currentTitle] = 'title';