Php 如何将数据值与数组值匹配
因此,我试图将数据库中的值与数组中的值进行匹配 这是数据库中的数据Php 如何将数据值与数组值匹配,php,arrays,match,explode,array-intersect,Php,Arrays,Match,Explode,Array Intersect,因此,我试图将数据库中的值与数组中的值进行匹配 这是数据库中的数据 $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 $ge
$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";
}
}
}
$verdeel=explode(“,”,$data['product']);
$getallen=数组(“10”、“20”);
if(数组相交($verdeel,$getallen)){
对于($i=0;$i
现在输出为:没有匹配项
没有匹配项
没有匹配项
没有匹配项
没有匹配项
我只想输出与数据库中某些值匹配的数组值 谢谢
样本:
还是你的意思 Array_intersect已返回一个包含所需值的数组。。。因此,如果要比较的数组中的值相同,则得到该数组的null。。
<?php
$os = array("Mac", "NT", "Irix", "Linux");
if (in_array("Irix", $os)) {
echo "Got Irix";
}
if (in_array("mac", $os)) {
echo "Got mac";
}
?>
$verdeel = explode(", ", $data['product']);
$getallen = array("10", "20");
$someArray = array_intersect($verdeel, $getallen);
if($someArray != null){
//DO STUFF
} else {
//NO MATCH
}