combine 2 values in json foreach

Solution 1:

If you want to continue the way you started, for each channel you have to check every user :

foreach($result['channels'] as $item){     
   echo '<div class="channel">
           <div class="channel-name">'.$item['name'].'</div>';           

          foreach($result['members'] as $member){   
            if(isset($member['channel_id']) && !strcmp($member['channel_id'], $item['id'])) {
                echo $member['username'];
            }
          }

   echo '</div>';
}

Is this what you want ?

Doc :
https://php.net/strcmp
https://php.net/isset