Sample:
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
or Did you mean? compare to array
Question
So i'm trying to match the values from the database with values from an array.
This is the data from database
$verdeel = explode(", ", $data['product']);
$getallen = array("10", "20");
if(array_intersect($verdeel, $getallen)){
for($i=0;$i < count($verdeel);$i++){
if($verdeel[$i] == $getallen[$i]){
echo $getallen[$i];
} else {
echo "no match";
}
}
}
output will be now:
no match
no match
no match
no match
no match
I just want to only output the values of the array that match with some of the values in the database.
Thank you
Solution
Sample:
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
or Did you mean? compare to array
OTHER TIPS
$verdeel = explode(", ", $data['product']);
$getallen = array("10", "20");
$someArray = array_intersect($verdeel, $getallen);
if($someArray != null){
//DO STUFF
} else {
//NO MATCH
}