I need one help. I need to verify weather one json array value is present inside another array or not using PHP. I am explaining my code below.
$img=array(
array("iamge"=>"1234_asd.jpg"),
array("iamge"=>"1235_ase.jpg"),
array("iamge"=>"1236_asf.jpg")
);
$imgArr=array(
array("iamgename"=>"1234_asd.jpg"),
array("iamgename"=>"1235_ase.jpg"),
array("iamgename"=>"1236_asf.jpg"),
array("iamgename"=>"1237_asg.jpg")
);
Here I have two array. I need to check any of value from $imgArr
array is present inside $img
array or not.In case any value is not present it will return false with that image name
and if all present it will return omlu true
. Please help me.
$match = array();
foreach ($imgArr as $imgArray){
foreach ($img as $imgg){
if($imgArray['iamgename'] == $imgg['iamge']){
$match[]=$imgArray['iamgename'];
}
}
}
print_r($match);
function bjsearch($img, $seachimg){
$result = true;
if(!in_array($seachimg, $img)){
$result = false;
}
return $result;
}
$found = true;
$image_name = '';
foreach($imgArr as $k=>$im){
$seachInArr = isset($img[$k]) ? $img[$k] : array();
$res = bjsearch($seachInArr, $im['iamgename']);
if($res === false){
$found = false;
$image_name = $im['iamgename'];
}
}
var_dump($found, $image_name);
Working Example: https://3v4l.org/vkAF4