I have a string from database that I want to match with an array but it results in error saying:
strpos(): Empty needle in line X
if (!isset($_SESSION['arry'])) {
$_SESSION['arry'] = array();
}
$imp = 42;
$arrys = $_SESSION['arry'];
foreach($arrys as $string)
{
if(strpos($imp, $string) !== false)
{
$pow =1;
break;
}
}
if($pow==1){ exit; }
Array
(
[0] => 218
[1] => 219
[2] => 218
[3] => 220
[4] => 222
[5] => 42
[6] => 223
)
You are doing the opposite way , searching string in 42 , instead go for
strpos($string, $imp)
and as @abracadaver added you can use in_array
TRY THIS : (updated)
foreach($arrys as $string)
{
if(strpos($string, $imp) !== FALSE)
{
$pow =1;
break;
}
}