tags:

views:

93

answers:

5

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 
           [icon] => icon.png 
           [n_url] => wall_action.php?id=930 
           [desc] => 690706096 
           [text] => Array ( [0] => Sarah O'conner ) [total] => 1 )))
+4  A: 
$arr['notifys'][0]['icon']
Dobiatowski
that's either not working, it returns nothing
clonex1
post some moer code, becouse we showed you the code to your array sample
Dobiatowski
+8  A: 
$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.

SilentGhost
that's not working, it returns nothing
clonex1
@clonex1: Yet you accepted it. Care to explain?
Piskvor
@Piskvor: yeah, but explain what!
clonex1
@clonex1: you said "that's not working"; on the other hand, you selected "this is the right answer to my problem". So, I see a contradiction, and I don't understand *this*: is it working (then why the comment saying "it's not"?), or is it not (then why the accept meaning "it is"?)?
Piskvor
@Piskvor: it worked using $ar['notifys[0]['notifytype_id'];there was just syntax error aroundthanks Piskvor
clonex1
A: 
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"];
Pranav Negandhi
just tried it!its still not working, empty results
clonex1
A: 
$arr['notifys']['0']['icon']
Svisstack
A: 

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'];
rahijain