仅显示不包含[关闭]的数组值

foreach ($prefs as $who => $pref) {
 if($who != 'public'){
  $team_users .=$who.',';
  }
 }       
echo $team_users;

I'd like to only display data from the array that does not contain the text 'public' in some cases it could be publicXX or public1234, etc.

http://us3.php.net/strpos

if (strpos($who, 'public') === false) {
  //some code
} else {
  //some code
}

I'd like to only display data from the array that does not contain the text 'public' in some cases it could be publicXX or public1234, etc.

Change:

if($who != 'public'){...}

to this:

if(strpos($who, 'public') !== false){...}

You can use array_filter() with a callback to achieve this:

$result = array_filter($prefs, function($item) {
    return (strpos($item, 'public') === FALSE);
});
echo implode(',', $result);
foreach ($prefs as $who => $pref) {
    if(strpos($who, 'public') !== false){
        $team_users .=$who.',';
    }
}       
echo $team_users;

You can try something like this:

foreach ($prefs as $who => $pref) {
   if(!preg_match("/public/i", $who)){
       $team_users .= $who.',';
   }
} 
<?php

$a = array('public1', 'asdqwe', 'as33publics', 'helloworld');

$text = implode(', ', array_filter($a, function($v) {
    return strstr($v, 'public') === false;
}));

echo $text;

I would do it with regex.

$pattern = '/public/'; 

if(preg_match($pattern,$who)){
//skip to the next entry
}