简体   繁体   中英

Error displaying results from an in_array()

I tried comparing values in two arrays using in_array() . $friends[] contains all ids of my friends in the friends table while $membersarray[] contains ids of people in a team.

What I'm trying to do here using in_array() is that I want only friends ids who are not part of the team to show up and it worked. But now, I want the result ( $t ) to display the surnames stored in the friends table instead of just the ids.

For example, it shows: 3, 5 and 7. I want it to show, 'john', 'doe' and 'rick'. How do I do this?

$friends[] = $record5['id']; //contains of ids of all friends

$membersarray[] = $output['id']; //contains ids of all team members

foreach ($friends AS $t) {

   if (in_array($t, $membersarray)) {
   //donothing                         
   } else {
     echo $t;

     }
  }

You can use this syntax with empty brackets after the variable name:

$friends[] = $record5['id']; //adds one element to the array $friends

to add a single element to an array.

As long as $record5['id'] is already an array, you just need this:

$friends = $record5['id']; //contains ids of all friends

$membersarray = $output['id']; //contains ids of all team members

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM