0
我有兩個數組。一個來自數據庫,我可以訂購我想要的。
第二個來自第三方api,我無法控制訂單。我試圖根據三個密鑰(pk1
,pk2
,pk3
)確定差異,如$desired
下所示。採用獨特的鍵給定鍵上的二維PHP數組的區別
$array1=[
["pk1"=>1,"pk2"=>1,"pk3"=>1,"attr1"=>1,"attr2"=>3],
["pk1"=>1,"pk2"=>2,"pk3"=>1,"attr1"=>3,"attr2"=>1],
["pk1"=>1,"pk2"=>1,"pk3"=>2,"attr1"=>2,"attr2"=>3],
];
$array2=[
["pk1"=>2,"pk2"=>2,"pk3"=>1,"attr1"=>3,"attr2"=>1],
["pk1"=>1,"pk3"=>2,"pk2"=>1,"attr1"=>4,"attr2"=>3],
["pk1"=>1,"pk2"=>1,"pk3"=>1,"attr1"=>1,"attr2"=>3],
];
$desired=[
["pk1"=>1,"pk2"=>1,"pk3"=>1,"array1"=>["attr1"=>1,"attr2"=>3],"array2"=>["attr1"=>1,"attr2"=>3]],
["pk1"=>1,"pk2"=>2,"pk3"=>1,"array1"=>["attr1"=>3,"attr2"=>1],"array2"=>null],
["pk1"=>1,"pk2"=>1,"pk3"=>2,"array1"=>["attr1"=>2,"attr2"=>3],"array2"=>["attr1"=>4,"attr2"=>3]],
["pk1"=>2,"pk2"=>2,"pk3"=>1,"array1"=>null,"array2"=>["attr1"=>3,"attr2"=>1]]
];
你將不得不詳細解釋你的問題,它的代碼並不明顯 – Steve
從'pk's創建唯一的密鑰並進行比較。 –
@u_mulder我現在開始這樣做,使用'$ array [「$ arr [pk1]〜$ arr [pk2]〜$ arr [pk3]」]'這是你的意思嗎? – user1032531