开发者

Help me grab a value from a multidimensional PHP array

开发者 https://www.devze.com 2023-03-03 20:10 出处:网络
I can\'t seem to get this value.here is the array: [1596] => Array ( [entry_id] => 1596 [title] => This is the article title

I can't seem to get this value. here is the array:

[1596] => Array
(
    [entry_id] => 1596
    [title] => This is the article title
    [url_title] => url-title-here
    [status] => open
    [entry_date] => 1304544513
    [alt_title] => 
    [article_summary] => This is the article summary
    [article_intro] => This is the article intro
    [article_image] => 
    [article_body] => This is the article body
    [article_media_id] => 1
    [article_videos] => 
    [article_media] => Array
        (
            [0] => Array
                (
                    [row_id] => 3730
                    [row_order] => 0
                    [col_id_7] => image
                    [col_id_12] => right
                    [col_id_8] => 9781400068609.jpg
                    [col_id_9] => 
                    [col_id_10] => 
                    [col_id_54] 开发者_高级运维=> 
                )

        )

)

I am trying to build a URL using

'http://www.domain.com/uploads/media/'.$entry['entry_id']['article_media'][0]['col_id_8']

but it keeps giving me a '1' at the end of that image value. it should be 9781400068609.jpg, right? What do I have wrong?


['entry_id'] is derailing your path. You'll want to refer to the top-level key by its number (probably in a variable) like this:

$entry_id = 1596;
$valueYouWant = $entry[$entry_id]['article_media'][0]['col_id_8'];


For example, if your array is called entry, then

$entry['entry_id'] == 1596

you must write instead:

$entry['article_media'][0]['col_id_8']


You have to specify the ID 1596 not 'entry_id' if $entry is the array holding all entries

$entry[1596]['article_media'][0]['col_id_8']


$entryId = 1596;
$entries[$entryId]['article_media'][0]['col_id_8']
0

精彩评论

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