假设我有一个多维数组。例如:
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 )
)
我想将所有蛇与蛇进行比较,将所有熊猫与熊猫等进行比较(但不是蛇与熊猫进行比较)并将唯一元素放入一个数组中(所有唯一元素放入一个数组中),我将如何去做这件事。由于它们是数组中的元素,我有点难过。另外,我不会提前知道会有多少种不同的类型。例如,有一次我可以传递一个包含 Panda、Bear、Snake 的多维数组——下一次我可以传递一个包含 Bird、Cat、Panda、Zebra 的数组。
有任何想法吗?
最终输出
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 )
)