0

我需要找到哪个是包含值部分的键并且不显示它

$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;
          }
    }
4

3 回答 3

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);
于 2013-10-14T13:40:56.163 回答
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;
    }
}
于 2013-10-14T13:41:07.830 回答
0
echo $arr;
       ^

应该是 $key 或 $value;

于 2013-10-14T13:40:36.313 回答