使用php循环比较三个数组/json的内容
我有一个包含许多行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”))。; //{“哈
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);