0

First, I'd like to apologize in advance for my approximate English (I'm French) :)

I have the following array and can't figure out how to get the data out:

array (size=3)
  0 => 
    object(stdClass)[23]
      public 'id_photo' => string '14' (length=2)
      public 'id_user' => string '40' (length=2)
      public 'titre' => string 'Ma 2e TOF Mimi' (length=14)
      public 'taille' => string '54' (length=2)
      public 'nom' => string 'debutScript.PNG' (length=15)
  1 => 
    object(stdClass)[24]
      public 'id_photo' => string '12' (length=2)
      public 'id_user' => string '39' (length=2)
      public 'titre' => string 'Ma TOF Seb' (length=10)
      public 'taille' => string '16' (length=2)
      public 'nom' => string 'BDD.PNG' (length=7)
  2 => 
    object(stdClass)[25]
      public 'id_photo' => string '13' (length=2)
      public 'id_user' => string '40' (length=2)
      public 'titre' => string 'Ma TOF Mimi' (length=11)
      public 'taille' => string '24' (length=2)
      public 'nom' => string 'COMMUNE.PNG' (length=11)

This is the result of var_dump($res);

I want to know how to display in the var_dump only the objects with id_user are equal to 40 => an array with 2 objects. So concretely I would like to know how to access to id_user of every object.

Thanks in advance.

1
  • 3
    You can iterate over the items of the array foreach($res as $item) and then check if the id matches your expectations: $item->id_user >= 40 Commented Feb 27, 2020 at 16:23

1 Answer 1

1

You can traverse the array as follows

foreach($data as $row){
   if($row->id_user == 40){
      //desired actions you want to perform
   }
}

I hope that helps you.

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

2 Comments

Thank you that's really help me :)
Glad that it helped you. Please accept the answer and upvote if possible.

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.