2

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 )))
1
  • i accessed total using, $arr['total'] the result was 2 i tried to access the notifytype_id value which its 12 using $arr['notifys][0]['notifytype_id'] the result was nothing :( i tried the first 3 answer and the result still nothing Commented Jul 12, 2010 at 11:32

4 Answers 4

8
$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.

Sign up to request clarification or add additional context in comments.

3 Comments

@Piskvor: yeah, but explain what!
@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: it worked using $ar['notifys[0]['notifytype_id']; there was just syntax error around thanks Piskvor
4
$arr['notifys'][0]['icon']

1 Comment

post some moer code, becouse we showed you the code to your array sample
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"];

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.