foreach ($prefs as $who => $pref) {
if($who != 'public'){
$team_users .=$who.',';
}
}
echo $team_users;
我只想显示数组中不包含文字' public'在某些情况下,它可能是publicXX或public1234等。
答案 0 :(得分:2)
您可以使用array_filter()
进行回调来实现此目的:
$result = array_filter($prefs, function($item) {
return (strpos($item, 'public') === FALSE);
});
echo implode(',', $result);
答案 1 :(得分:1)
if (strpos($who, 'public') === false) {
//some code
} else {
//some code
}
答案 2 :(得分:0)
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.
变化:
if($who != 'public'){...}
到此:
if(strpos($who, 'public') !== false){...}
答案 3 :(得分:0)
foreach ($prefs as $who => $pref) {
if(strpos($who, 'public') !== false){
$team_users .=$who.',';
}
}
echo $team_users;
答案 4 :(得分:0)
您可以尝试这样的事情:
foreach ($prefs as $who => $pref) {
if(!preg_match("/public/i", $who)){
$team_users .= $who.',';
}
}
答案 5 :(得分:0)
<?php
$a = array('public1', 'asdqwe', 'as33publics', 'helloworld');
$text = implode(', ', array_filter($a, function($v) {
return strstr($v, 'public') === false;
}));
echo $text;
答案 6 :(得分:0)
我会用正则表达式来做。
$pattern = '/public/';
if(preg_match($pattern,$who)){
//skip to the next entry
}