<?php$nodes = array( "parent node", "parent node", array( "child node", "child node", array( "grand child node", "grand child node" ) ));$s = '<node>';$arr = $nodes;while(count($arr) > 0){ $n = array_shift($arr); if(is_array($n)) { array_unshift($arr, null); $arr = array_merge($n, $arr); $s .= '<node>'; } elseif(is_null($n)) $s .= '</node>'; else $s .= '<node>'.$n.'</node>';}$s .= '</node>';echo $s;?>


