php怎么遍历一个复杂的多维数组

WBOY
Release: 2016-06-13 13:37:31
Original
1227 people have browsed it

php如何遍历一个复杂的多维数组
比如有这样一个数组,毫无规律,怎么遍历?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
$arr=array(
 array(array('val1','val2','val3'),'aa','bb'),
 'php',
'apache',
 array('hello','world')
);

Copy after login


------解决方案--------------------
你遍历后想做什么? 可以用递归处理
PHP code
// 作为回调函数。 参数将不会是数组
function doSomething($value) 
{
     echo $value;
}
function look(array $array)
{
     foreach($array as $value)
     {
         // 如果仍为数组,则继续遍历
         if(is_array($value))
             look($value);
         else
             call_user_func('doSomething', $value);
     }
} <div class="clear">
                 
              
              
        
            </div>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template