查找字符串的一部分并将其从数组中删除 [英] Find part of a string and remove it from an array
本文介绍了查找字符串的一部分并将其从数组中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要找到哪个键包含值的一部分并且不显示它
i need to find which is the key containing the part of the value and doesn't show it
$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;
}
}
推荐答案
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);
这篇关于查找字符串的一部分并将其从数组中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文