Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/239.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 匹配数组值_Php_Arrays - Fatal编程技术网

Php 匹配数组值

Php 匹配数组值,php,arrays,Php,Arrays,我有两个这样的阵列: [a] => Array ( [w] => 90 [h] => 90 ) [b] => Array ( [w] => 40 [h] => 25 ) 以及: 如何确定第一个数组中的W和H元素是否与第二个数组中的元素匹配,以及它们是否获得匹配元素的name值 // $arrayWithNamesInIt is t

我有两个这样的阵列:

[a] => Array
    (
        [w] => 90
        [h] => 90       
    )

[b] => Array
    (
        [w] => 40
        [h] => 25         
    )
以及:

如何确定第一个数组中的W和H元素是否与第二个数组中的元素匹配,以及它们是否获得匹配元素的
name

// $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'];
    }
}

不,我只有两个,但它们是多维的
// $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'];
    }
}