🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
[TOC] ## 概述 ``` /* 方法 */ public getChildren ( ) : RecursiveArrayIterator public hasChildren ( ) : bool ``` ## 实例 ``` $myArray = array( 0 => 'a', 1 => array('subA','subB',array(0 => 'subsubA', 1 => 'subsubB', 2 => array(0 => 'deepA', 1 => 'deepB'))), 2 => 'b', 3 => array('subA','subB','subC'), 4 => 'c' ); $iterator = new RecursiveArrayIterator($myArray); iterator_apply($iterator, 'traverseStructure', array($iterator)); /** * @param RecursiveArrayIterator $iterator */ function traverseStructure($iterator) { while ( $iterator -> valid() ) { if ( $iterator -> hasChildren() ) { traverseStructure($iterator -> getChildren()); } else { echo $iterator -> key() . ' : ' . $iterator -> current() .PHP_EOL; } $iterator -> next(); } } //0 : a //0 : subA //1 : subB //0 : subsubA //1 : subsubB //0 : deepA //1 : deepB //2 : b //0 : subA //1 : subB //2 : subC //4 : c ```