0

I have an array which I can't seem to access properly, been trying to echo the address. It's called $user and here is the print_r for it:

Array(    
    [0] => stdClass Object        
    (            
        [id] => 1            
        [firstname] => Casper            
        [lastname] => *lastname*            
        [email] => someEmail            
        [username] => aUsername            
        [password] => *encrypted password*            
        [address] => myAddress            
        [address2] =>             
        [city] =>             
        [state] =>             
        [zipcode] => 1111            
        [join_date] => current timestamp        
    )
)
1

It's in codeigniter and so far I've tried:

echo $user['address'];

echo $user->address;

Both of them with no luck. Any help is greatly appriciated

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
Niantic
  • 43
  • 8

1 Answers1

5

You have a multi-dimensional array and the first index is 0, also inside the first index you have the object. to access an array of object you need to use ->

You have to echo like given code:

echo $user[0]->address;

Murad Hasan
  • 9,565
  • 2
  • 21
  • 42