I am trying to check if a user input value exists in a array list using PHP. Here is my code:
$chkvalue=$_POST['id'];
$sql=$dbh->prepare("my query hear");
$sql->execute();
$memers=$sql->fetch(PDO::FETCH_BOTH);
I got my list of values in array $memers
. When I use var_dump($memers);
I can see all the values in the array. Now, I want to check weather $chkvalue
exists in the array $memers
.
I tried the code below:
if (in_array($chkvalue ,$memers)) {
echo "Value exists";
} else {
echo "Value doesn't exists";
}
But, it is always showing Value doesn't exists
.
For example: my array contains {23568,456982,123489,125895,154879,124648}
Now I want to check if 456982 exists in that array or not.
i tried FETCH_NUM
i got below result
array(5) { [0]=> string(6) "600258" [1]=> string(15) "A SURYANARAYANA" [2]=> string(6) "420575" [3]=> string(1) "A" [4]=> string(10) "2016-07-05" }
array(5) { [0]=> string(6) "223511" [1]=> string(20) "A UMA MAHESWARA RAO" [2]=> string(6) "600258" [3]=> string(1) "A" [4]=> string(10) "2016-07-05" }
array(5) { [0]=> string(6) "907774" [1]=> string(19) "A UMA MAHESWARA RAO" [2]=> string(6) "223511" [3]=> string(1) "A" [4]=> string(10) "2016-07-05" }
array(5) { [0]=> string(6) "688108" [1]=> string(13) "M BALA BALAJI" [2]=> string(6) "907774" [3]=> string(1) "A" [4]=> string(10) "2016-07-05" }