<?php
header('Access-Control-Allow-Origin: *');
include "includes/config.php";
include "includes/session.php";
include "includes/functions.php";
include_once('classes/cls_products.php');

$categoryId         =   $_REQUEST['catID'];
$existCagoryId      =   $_REQUEST['existCagoryId'];

function getArrayDiff($a1, $a2) {
    $result = array();
    // If First Array is Bigger than Second
    if( count($a1) > count($a2) ) {
        $result=array_diff($a1,$a2);
    }
    // If Second Array is Bigger than First
    if( count($a1) < count($a2) ) {
        $result=array_diff($a2,$a1);
    }
    // If Both array are same but, data values are different.
    else
    {
        $result = array_merge (array_diff($a2,$a1), array_diff($a1,$a2));   
    }
    return $result;
}

$newArray =  array();

$categoryOptions = Products::getCategoryOptionsValues($categoryId);

//echopre($categoryOptions);

$categoryExistOptions = Products::getCategoryOptionsValues($existCagoryId);

//echopre($categoryExistOptions);

$existArray = array();
if(!empty($categoryExistOptions))
{
   
    foreach($categoryExistOptions as $eid)
    {
        $existArray[]= $eid->option_id;
    }
   
   // $existArray = serialize($existArray);
    
   
}

 $categoryArray = array();
 
if(!empty($categoryOptions))
{
   
    foreach($categoryOptions as $cid)
    {
        $categoryArray[]= $cid->option_id;
    }
    
   
   // $categoryArray = serialize($categoryArray);
    
}
$newArray =  getArrayDiff($existArray,$categoryArray);

if (empty($newArray)) {
    $array = array('status'=>'0'); // success
}else{
    $array = array('status'=>'1'); // failed
}

echo json_encode($array);

exit;
