dongmangji0950
dongmangji0950
2014-07-31 09:12

循环遍历多维数组并查找匹配值

  • if-statement
  • for-loop
  • php

I'm looking for a way to loop through a multidimensional array and with an if (or simular) find matching values if key master is true.

The array:

    Array
(
    [0] => Array
        (
            [namn] => Vardagsrum
            [IP] => 192.168.1.232
            [rincon] => RINCON_000E58A64F1601400
            [rincon_live] => RINCON_000E58A64F1601400
            [master] => 1
        )

    [1] => Array
        (
            [namn] => Badrum
            [IP] => 192.168.1.137
            [rincon] => RINCON_B8E937580A5801400
            [rincon_live] => RINCON_000E58A64F1601400
            [slave] => 1
        )

    [2] => Array
        (
            [namn] => Kök
            [IP] => 192.168.1.134
            [rincon] => RINCON_000E58F8C9E001400
            [rincon_live] => RINCON_000E58A64F1601400
            [slave] => 1
        )

)

If i got a master => true (in this case vardagsrum) I would like the loop to match all slave => true rincon_live values against the masters rincon value.

I dont know if that makes any sense at all but if I got one or more masters, I want to check the slaves rincon against the masters to see which slaves is connected to which master and after that do something.

Thanks for the help!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐