开发者

PHP adding specific values into pre-existing array

开发者 https://www.devze.com 2023-02-19 05:46 出处:网络
I have an array: $availAds[$imageFile] = array( \'image\' => $imageFile, \'title\' => $artDetails[0],

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';
0

精彩评论

暂无评论...
验证码 换一张
取 消