tags:

views:

19

answers:

2

I have a multidim array that I can view using print_r($users):

Array
(
    [0] => stdClass Object
        (
            [username] => crustacea
            [created_on] => 2010-08-07 19:54:32
            [active] => 1
        )
)

I can also use print_r($users[0]). Since there's only one member in $users, the output looks somewhat the same.

I can't see how to retrieve the value crustacea. echo $users[0]['username']; doesn't do it. Examples I can find are echo $users['name_of_array']['username']; -- but I don't have a name of array to work with. How do I do it?

+1  A: 

$user[0] is not an array but an object as indicated by [0] => stdClass Object.

echo $users[0]->username;
VolkerK
A: 

$user[0] is object and not an array. You can access your value by doing

$users[0]->username;

Or you could cast/convert your object into an array like

((array)$users[0])['username'];
DrDol
I am accepting the other answer merely because it came in earlier. I appreciate the extra tip on casting as array. Thanks very much.
Smandoli
No problem. I'm not 'reputation' points addicted. ;-)
DrDol