数组与字符串PHP比较

时间:2014-12-17 07:35:30

标签: php arrays string

我的数组结果是

  Array ( [list] => Bhubaneswar,Cuttack,Angul,Sambalapur )

我想比较这个PHP数组,在列表中是congaing" Bhubaneswar'不是吗?

2 个答案:

答案 0 :(得分:0)

你可能想看一下这个:

in_array()

http://php.net/manual/en/function.in-array.php

答案 1 :(得分:-1)

试试这个:

$your_array = array(
    "list" => 'Bhubaneswar,Cuttack,Angul,Sambalapur',
    );
$mystring = $your_array['list'];
$findme   = 'Bhubaneswar';
if(strpos($mystring, $findme) !== false){
    echo "found";
}

OR

$search = preg_quote('Bhubaneswar', '~'); // don't forget to quote input string!
$your_array = array(
    "list" => 'Bhubaneswar,Cuttack,Angul,Sambalapur',
    );
$result = preg_filter('~' . $search . '~', null, $your_array);

echo "<pre>";
print_r(array_keys($result));