Iterating over a complex Associative Array in PHP

后端 未结 7 1934
广开言路
广开言路 2020-11-27 17:00

Is there an easy way to iterate over an associative array of this structure in PHP:

The array $searches has a numbered index, with between 4 and 5 assoc

7条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 17:41

    Looks like a good place for a recursive function, esp. if you'll have more than two levels of depth.

    function doSomething(&$complex_array)
    {
        foreach ($complex_array as $n => $v)
        {
            if (is_array($v))
                doSomething($v);
            else
                do whatever you want to do with a single node
        }
    }
    

提交回复
热议问题