我需要找到哪个是包含值的一部分的键而不显示它
$arr = array(0 => "helbor_000", 1 => "ez_000", 2 => "xx_333");
$find = "helb";
$key = array_search($find, $arr);
foreach($arr as $index => $value){
if($index != $key){
echo $value;
}
}
答案 0 :(得分:2)
preg_grep()
可以做到
$arr = array(0 => "helbor_000", 1 => "ez_000", 2 => "xx_333");
$find = "~^helb.*$~";
$ret = preg_grep($find, $arr, PREG_GREP_INVERT);
print_r($ret);
答案 1 :(得分:1)
$arr = array(0 => "helbor_000", 1 => "ez_000", 2 => "xx_333");
$find = "helb";
foreach($arr as $index => $value){
if(strpos($value, $find) === false) {
echo $value, PHP_EOL;
}
}
答案 2 :(得分:0)
echo $arr;
^
应为$ key或$ value;