PHP adding specific values into pre-existing array
I have an array:
$availAds[$imageFile] = array(
'image' => $imageFile,
'title' => $artDetails[0],
'link' => $artDetails[1]
);
and I have values that开发者_如何学JAVA need to be added to the array and assigned the same values based on there content:
foreach($querytitle as $currentTitle ):
$titlearray = $currentTitle->nodeValue ;
array_push( $availArts,$titlearray );
endforeach;
I'm using array_push and that adds it to the array fine, but I ened to be able to assign 'title' to $currentTitle.
Hope this makes sense, and thanks.
You should refer to the php.net array documentation.
Simply put, you can add items to arrays in a few ways:
$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
$availArts[$currentTitle] = 'title';
精彩评论