in_array() and multidimensional array

前端 未结 22 1850
眼角桃花
眼角桃花 2020-11-22 00:30

I use in_array() to check whether a value exists in an array like below,

$a = array(\"Mac\", \"NT\", \"Irix\", \"Linux\");
if (in_array(\"Irix\"         


        
22条回答
  •  猫巷女王i
    2020-11-22 01:04

    I used this method works for any number of nested and not require hacking

     [
                'golang',
                'php',
                'ruby',
                'functional' => [
                    'Erlang',
                    'Haskell'
                ]
            ],
            'bd' => [
                'mysql',
                'sqlite'
            ]
        ];
        $it = new RecursiveArrayIterator($blogCategories);
        foreach (new RecursiveIteratorIterator($it) as $t) {
            $found = $t == 'Haskell';
            if ($found) {
               break;
            }
        }
    

提交回复
热议问题