문제

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

도움이 되었습니까?

해결책

in_array()


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

다른 팁

$verdeel = explode(", ", $data['product']);

$getallen = array("10", "20");

$someArray = array_intersect($verdeel, $getallen);

if($someArray != null){
    //DO STUFF
} else {
    //NO MATCH
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top