我怎么能访问这样的PHP数组

时间:2010-07-12 11:20:35

标签: php arrays

我试图访问这个PHP数组没有运气,我想访问[icon] =>的icon.png

Array ( [total] => 2 
  [total_grouped] => 2 
  [notifys] => Array ( [0] => Array ( [notifytype_id] => 12 
           [grouped] => 930 
           [icon] => icon.png 
           [n_url] => wall_action.php?id=930 
           [desc] => 690706096 
           [text] => Array ( [0] => Sarah O'conner ) [total] => 1 )))

4 个答案:

答案 0 :(得分:8)

$arr['notifys'][0]['icon']

ETA :我不确定您的评论意味着什么,以下代码:

$arr = array('total'=>2, 'total_grouped' => 2, 'notifys' => array(array(
'notifytype_id' => 12, 'icon' => 'icon.png')));
echo '<pre>';
print_r($arr);
echo '</pre>';
var_dump($arr['notifys'][0]['icon']);

输出:

Array
(
    [total] => 2
    [total_grouped] => 2
    [notifys] => Array
        (
            [0] => Array
                (
                    [notifytype_id] => 12
                    [icon] => icon.png
                )

        )

)

string(8) "icon.png" 

通常,代码永远不会输出任何内容。您应该开发所有错误和通知。

答案 1 :(得分:4)

$arr['notifys'][0]['icon']

答案 2 :(得分:0)

rg = Array ( [total] => 2 [total_grouped] => 2 [notifys] => Array ( [0] => Array ( [notifytype_id] => 12 [grouped] => 930 [icon] => icon.png [n_url] => wall_action.php?id=930 [desc] => 690706096 [text] => Array ( [0] => Sarah O'conner ) [total] => 1 )));
icon = rg["notifsys"][0]["icon"];

答案 3 :(得分:0)

每个人都在发表正确答案。它只是你给出了一个错误的数组减速。

尝试数组的var_dump / print_r,然后您就可以轻松了解节点。

$arr = array(total => 2, 
    total_grouped => 2, 
    notifys => array( 0 => array(notifytype_id => 12, 
        grouped => 930,
        icon => 'icon.png', 
        n_url => 'wall_action.php?id=930', 
        desc => 690706096,
        text =>array(0 => 'Sarah Oconner' ),
        total => 1, 
        ),
    ),
);

echo $arr['notifys']['0']['icon'];