php 比较数组中的元素,php – 比较多维数组中的元素
說我有一個(gè)多維數(shù)組.例如:
Array (
[0] => Array (
[animal_id] => 5494
[animal_name] => "Suzy"
[animal_type] => "zebra"
[animal_location] => 0
[animal_awake] => 1
[animal_age] => 3 )
[1] => Array (
[animal_id] => 5494
[animal_name] => "Joshua"
[animal_type] => "panda"
[animal_location] => 5
[animal_awake] => 0
[animal_age] => 8 )
[2] => Array (
[animal_id] => 5494
[animal_name] => "Debra"
[animal_type] => "snake"
[animal_location] => 7
[animal_awake] => 1
[animal_age] => 3 )
[3] => Array (
[animal_id] => 5495
[animal_name] => "Caleb"
[animal_type] => "zebra"
[animal_location] => 0
[animal_awake] => 1
[animal_age] => 3 )
[4] => Array (
[animal_id] => 5495
[animal_name] => "Joshua"
[animal_type] => "panda"
[animal_location] => 5
[animal_awake] => 0
[animal_age] => 8 )
[5] => Array (
[animal_id] => 5495
[animal_name] => "Debra"
[animal_type] => "snake"
[animal_location] => 7
[animal_awake] => 1
[animal_age] => 3 )
[6] => Array (
[animal_id] => 5496
[animal_name] => "Emily"
[animal_type] => "zebra"
[animal_location] => 0
[animal_awake] => 1
[animal_age] => 3 )
[7] => Array (
[animal_id] => 5496
[animal_name] => "Joshua"
[animal_type] => "panda"
[animal_location] => 5
[animal_awake] => 0
[animal_age] => 8 )
[8] => Array (
[animal_id] => 5496
[animal_name] => "Debra"
[animal_type] => "snake"
[animal_location] => 7
[animal_awake] => 1
[animal_age] => 3 )
)
我想比較所有的蛇與蛇,以及所有的熊貓對抗熊貓的等(但不是對熊貓的蛇)并將獨(dú)特的元素放入一個(gè)數(shù)組(所有獨(dú)特的元素組成一個(gè)陣列),我將如何這樣做.因?yàn)樗鼈兪菙?shù)組中的元素,所以我有點(diǎn)難過.此外,我不會事先知道會有多少種不同的類型.例如,有一次我可以通過Panda,Bear,Snake的多維數(shù)組傳遞 – 下一次我可以通過Bird,Cat,Panda,Zebra傳遞數(shù)組.
有任何想法嗎?
最終輸出
Array (
[0] => Array (
[animal_id] => 5494
[animal_name] => "Suzy"
[animal_type] => "zebra"
[animal_location] => 0
[animal_awake] => 1
[animal_age] => 3 )
[1] => Array (
[animal_id] => 5494
[animal_name] => "Joshua"
[animal_type] => "panda"
[animal_location] => 5
[animal_awake] => 0
[animal_age] => 8 )
[2] => Array (
[animal_id] => 5495
[animal_name] => "Caleb"
[animal_type] => "zebra"
[animal_location] => 0
[animal_awake] => 1
[animal_age] => 3 )
[3] => Array (
[animal_id] => 5495
[animal_name] => "Debra"
[animal_type] => "snake"
[animal_location] => 7
[animal_awake] => 1
[animal_age] => 3 )
[4] => Array (
[animal_id] => 5496
[animal_name] => "Emily"
[animal_type] => "zebra"
[animal_location] => 0
[animal_awake] => 1
[animal_age] => 3 )
)
總結(jié)
以上是生活随笔為你收集整理的php 比较数组中的元素,php – 比较多维数组中的元素的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python可以在excel中应用吗,p
- 下一篇: php 换行替换成p,php 换行如何替