Check if two arrays are equal

Check if two arrays are equal

<?php
// items from db
$array[] = [10, 20, 10];
$array[] = [10, 20, 201];
$array[] = [10, 20, 501];
$array[] = [10, 20, 601];
 
// new items
$arrayb[] = [10, 20, 10];
$arrayb[] = [10, 20, 20];
$arrayb[] = [10, 20, 50];
$arrayb[] = [10, 20, 60];
 
 
function compare(&$array,&$arrayb) {
    foreach ($array as $k => $v) {
        foreach ($arrayb as $k2 => $v2) {
            if($v == $v2) {            
                unset($array[$k],$arrayb[$k2]); // removed matched items
            }
        }
    }
}
 
compare($array,$arrayb);
 
// delete all
print_r($array);
 
echo '============';
 
// insert all
print_r($arrayb);

Share This Blog

Comment

Do you want to get our quality service for your business?