我有两个这样的数组:
[a] => Array
(
[w] => 90
[h] => 90
)
[b] => Array
(
[w] => 40
[h] => 25
)
和
[a] => Array
(
[w] => 90
[h] => 90
[name] => test
)
[b] => Array
(
[w] => 40
[h] => 25
[name] => test2
)
如何判断第一个数组中的W和H元素是否与第二个数组中的W和H元素匹配,以及它们是否获得匹配元素的name
值?
答案 0 :(得分:-1)
// $arrayWithNamesInIt is the array with w, h, and name
// $array1 is the array with only w and h
$names = array(); // Will hold the names of matching entries
foreach ($arrayWithNamesInIt as $key => $values) {
if (isset($array1[$key]) && $values['w'] == $array1[$key]['w'] && $values['h'] == $array1[$key]['h']) {
$names[] = $values['name'];
}
}
(demo)