Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用php比较两个json数据一个是xml另一个是mysql?_Php_Mysql_Json_Xml_Laravel - Fatal编程技术网

如何使用php比较两个json数据一个是xml另一个是mysql?

如何使用php比较两个json数据一个是xml另一个是mysql?,php,mysql,json,xml,laravel,Php,Mysql,Json,Xml,Laravel,我有两个json多维数组,一个来自数据库,另一个来自我的公共路径,它是xml,我如何比较两个数据是否相同 一个数据来自数据库 $shipment = Shipment::take('10')->get()->toJson(); $ship = json_decode($shipment,TRUE); 作为xml文件来自本地存储的其他数据 $files = File::get(storage_path('xml\Last_FILSDCSEA.xml'

我有两个json多维数组,一个来自数据库,另一个来自我的公共路径,它是xml,我如何比较两个数据是否相同

一个数据来自数据库

     $shipment = Shipment::take('10')->get()->toJson();
     $ship =  json_decode($shipment,TRUE);
作为xml文件来自本地存储的其他数据

      $files = File::get(storage_path('xml\Last_FILSDCSEA.xml'));      
      $xml = simplexml_load_string($files, "SimpleXMLElement", LIBXML_NOCDATA);
      $json = json_encode($xml);
      //dd($json);
      $data = json_decode($json,TRUE);
下面比较一下

   if(($ship['JS_UniqueConsignRef']) == ($data['JS_UniqueConsignRef']))
    {

        $difference = array_diff_assoc($ship,$data);
        dd($difference);
    }

需要对此代码进行任何更改,请提供帮助?

我建议您使用
array\u diff
,通过使用它,您可以确保它们与JSON结构中的内容完全匹配

$ship = json_decode($shipment, TRUE);
$data = json_decode($json, TRUE);
$array_result = array_diff($ship,$data);

if(empty($array_result[0])) {     
    echo "they are same";
}

我建议您使用
array_diff
,通过使用它,您可以确保它们与JSON结构中的内容完全匹配

$ship = json_decode($shipment, TRUE);
$data = json_decode($json, TRUE);
$array_result = array_diff($ship,$data);

if(empty($array_result[0])) {     
    echo "they are same";
}

这两个json看起来像什么?它还包含具有多个数据的多维数组。这两个json看起来像什么?它还包含具有多个数据的多维数组。根据数据结构,此函数仅检查n维数组的一个维度。我尝试这两种方法,但我无法比较整个数据,因为它有太多的数据。如果($sh['JS_uniquecoderef'])==($da['JS_uniquecoderef']){$difference=array_diff_assoc($ship,$data);dd($difference);}@munazzil这是我过去解决的方法。取决于数据结构,因为此函数只检查n维数组的一个维度。我尝试这两种方法,但我无法比较整个数据,因为它有太多的数据。如果($sh['JS_uniquetoffitref'])==($da['JS_uniquetoffitref']){$difference=array_diff_assoc($ship,$data);dd($difference);}@munazzil,这就是我过去解决的方法。