开发者

how can i access such a php array

i was trying to access this php array with no luck, i want to access the [icon] => icon.png

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


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

ETA: I'm not sure what your comment means, the following code:

$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']);

outputs:

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

        )

)

string(8) "icon.png" 

Generally, code never outputs nothing. You should be developing with all errors and notifications on.


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


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"];


Everybody is posting right answer. Its just you have giving a wrong deceleration of array.

Try var_dump/print_r of array and then you can easily understand nodes.

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜