0

Hello awesome programmers!

I am so sorry for the the novice question, however, I am having trouble finding a solution to my problem. I am attempting to run a for each loop through my array passed from my controller, however, the data being outputted is not the same as when I run a var_dump($array). I am thinking perhaps that I need to iterate through this object maybe? However, when I attempt to do so, I get a non-object error.

Controller:

$data['user_details'] = $this->ion_auth->user()->row();

View:

var_dump($user_details);
    foreach($user_details as $item){
        echo $item['email'];
    }

The output of this is : "21nfn4111NR12" but should be [email protected]!

I have also tried the object form:

var_dump($user_details);
    foreach($user_details as $item){
        echo $item->email;
    }

However, it results in error trying to get property of non-object!

When I run the var dump I get the following:

object(stdClass)#21 (17) {
  ["id"]=>
  string(1) "2"
  ["ip_address"]=>
  string(14) "119.132.127.01"
  ["username"]=>
  string(12) "roger petereson"
  ["password"]=>
  string(40) "fdZxF/RQo4nZKmbA5XQlwefbc8f8e5c74899c3d0"
  ["salt"]=>
  NULL
  ["email"]=>
  string(19) "[email protected]"
  ["activation_code"]=>
  NULL
  ["forgotten_password_code"]=>
  NULL
  ["forgotten_password_time"]=>
  NULL
  ["remember_code"]=>
  string(22) "44hjOlloLTIrkSrjSBVNie"
  ["created_on"]=>
  string(10) "1404939094"
  ["last_login"]=>
  string(10) "1405099607"
  ["active"]=>
  string(1) "1"
  ["first_name"]=>
  string(6) "Roger"
  ["last_name"]=>
  string(5) "Peterson"
  ["is_owner"]=>
  string(1) "1"
  ["user_id"]=>
  string(1) "2"
}
0

1 Answer 1

2

The following line:

$this->ion_auth->user()->row(); 

returns an object not an array (check your var_dump output), so you just need to

echo $user_details->email;
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your reply koala_dev! This works perfectly. Would I have used a for each if $user_details was returning more than one row?
I really appreciate the help! Sorry it was such a noob question.
do you use ->result() in model function for returning result data?
@user3750179 no problem, please remember to mark this answer as accepted to let the community know your issue is now resolved.

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.