duanran3115 2011-08-01 11:54
浏览 9
已采纳

匹配数组值

I have two arrays like this:

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

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

And:

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

[b] => Array
    (
        [w] => 40
        [h] => 25         
        [name]  => test2
    )

How can I find out if the W and H elements from the 1st array match the ones from the second one, and if they do get the name value of the matched element ?

  • 写回答

1条回答 默认 最新

  • doucheng9304 2011-08-01 11:58
    关注
    // $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)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思