我正在尝试打印数组元素,这是内容"伟大的食物"只有字。我的数组
Array ( [0] => Great food and Great Atmosphere! Will definately go back before I leave!! [1] => Great place [2] => Great place )
答案 0 :(得分:2)
尝试使用strpos()
$arr = array('Great food and Great Atmosphere! Will definately go back before I leave!!', 'Great place', 'Great place');
$findme ='Great food';
foreach($arr as $a) {
if(strpos($a, $findme) !== false) {
$newarr[] = $a;
}
}
print_r($newarr);//Great food and Great Atmosphere! Will definately go back before I leave!!
如果您只想Great food
匹配更改if(strpos($a, $findme) !== false) {
到if($a == $findme) {
答案 1 :(得分:0)
您可以使用array_filter功能。
function match_string($element){
return strpos($element, 'Great food');
}
$matches = array_filter($input_array,"match_string");