Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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的内容_Php_Arrays_Json - Fatal编程技术网

使用php循环比较三个数组/json的内容

使用php循环比较三个数组/json的内容,php,arrays,json,Php,Arrays,Json,我有一个包含许多行JSON文档的系统,我想比较每一行和其他两行,如果第一行中存在最后一行的元素,则提取或打印第一行中剩余字段的内容。我不得不使用循环。我的问题是,当我打印时,会得到多次结果 例: echo-json_-encode($A=array(“哈哈”=>“宾果”,“双雄”=>“双雄”,“特洛伊”=>“特洛伊”))。; echo json_encode($B=数组(“哈哈”=>“宾果”)。; echo json_encode($C=数组(“trois”=>“trois”))。; //{“哈

我有一个包含许多行JSON文档的系统,我想比较每一行和其他两行,如果第一行中存在最后一行的元素,则提取或打印第一行中剩余字段的内容。我不得不使用循环。我的问题是,当我打印时,会得到多次结果

例:

echo-json_-encode($A=array(“哈哈”=>“宾果”,“双雄”=>“双雄”,“特洛伊”=>“特洛伊”))。
; echo json_encode($B=数组(“哈哈”=>“宾果”)。
; echo json_encode($C=数组(“trois”=>“trois”))。
; //{“哈哈”:“宾果”,“对决”:“对决”,“三重奏”:“三重奏”}第1行 //{“哈哈”:“宾果”}第2行 //{“trois”:“trois”}第3行
对于($i=0;$i我有点不确定您想要什么,但这将提供一个“双数”:


谢谢,但我必须使用循环,我有很多JSON/数组文档,我必须循环到它们中。。。
echo json_encode($A=array("haha"=>"BINGO","deux"=>"deux","trois"=>"trois")).'</br>';
echo json_encode($B=array("haha"=>"BINGO")).'</br>';
echo json_encode($C=array("trois"=>"trois")).'</br>';

//{"haha":"BINGO","deux":"deux","trois":"trois"} Line 1
//{"haha":"BINGO"} Line 2
//{"trois":"trois"} Line 3


for($i=0; $i<sizeof($A); $i++){
    for($j=0; $j<sizeof($B) ;$j++){
        for($k=0; $k<sizeof($C); $k++){
            if($A[haha]==$B[haha] AND $A[trois] == $C[trois]){
                print_r ($A[deux]);echo'</br>';

                /*Print
                deux
                deux
                deux */
                //I would like to print just one time 'deux'

                }
        }
    }
}
$A=array("haha"=>"BINGO","deux"=>"deux","trois"=>"trois");
$B=array("haha"=>"BINGO");
$C=array("trois"=>"trois");

$one_and_two = array_diff($A, $B);
$one_and_three = array_diff($A, $C);

$diffs = array_intersect($one_and_two, $one_and_three);

var_dump($diffs);