我有一个包含许多行 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'
}
}
}
}
有什么建议请,非常感谢!!
我有点不确定你想要什么,但这将提供一个"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);