doupiao1893 2011-03-24 04:35
浏览 27
已采纳

PHP将特定值添加到预先存在的数组中

I have an array:

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

and I have values that 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.

  • 写回答

2条回答 默认 最新

  • drnl10253 2011-03-24 04:52
    关注

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部