如何检查数组中是否存在值并使用PHP将值插入数据库

I need some help. I need to insert the the value if its present inside the user input array using PHP and MySQL. I am explaining my table below.

db_images:

id         image     subcat_id

Here I need to insert into above table as the following json array value.

$subcat=array(array("id"=>63),array("id"=>64));
$imageArr=array(array("image"=>"abc.png","id"=>63));

Here I need to match both array if any value from $subcat array is present inside the second (i.e-$imageArr) array then the resepective image will insert into the table and if not present the the blank image value will insert with the respective subcat_id . Please help.

For every element in the subcat array, you can iterate on the imageArr and check if the ids match (nested loop), like this:

foreach($subcat as $s) {
    $flag = false;

    foreach($imageArr as $i) {
        if ($s['id'] == $i['id']) {
            // insert ($i['image'], $s['id']) into db
            $flag = true;
            break;
        } 
    }

    if ($flag == false) {
        // insert $s['id'] into db
    }
}

Hi you can even do in the following way with the help of array_column and in_array with loop reduced.

<?php

$subcat=array(array("id"=>63),array("id"=>64));
$imageArr=array(array("image"=>"abc.png","id"=>63), array("image"=>"abc.png","id"=>65));

foreach($imageArr as $image){
    /* array_column will do the job with in_array to search in the multi dimension array */
    if(in_array($image['id'], array_column($subcat, 'id'))){
        echo 'exists'. $image['id'].'<br>'; 
    }else{
        echo 'not exists'. $image['id'].'<br>';
    }
}