note 21803 added to ref.array

From: Date: Tue, 28 May 2002 02:10:04 +0000
Subject: note 21803 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-31081@lists.php.net to get a copy of this message
here's a little function i wrote to convert any multidimensional array to an xml tree. it has this prototype: string arr2xml (array array, [string tree_name]) if they are associative arrays, the element keys will be used as node names. any numeric arrays will be filled in with level1, level2 .. if you omit the second (optional) argument, it uses level0 as the top of the tree. function arr2xml ($arr) { if (func_num_args () < 3) { $wrapper = (func_num_args < 2) ? array ($arr) : array (func_get_arg(1)=>$arr); $xml = arr2xml ($wrapper, '', 0); } else { $level = func_get_arg (2); while (list ($key, $val) = each ($arr)) { if ($key === (int)$key) $key = 'level'.$level; $xml .= '<'.$key.'>'; if (gettype ($val) == 'array') { $xml .= arr2xml ($val, '', $level+1); } else { $xml .= $val; } $xml .= '</'.$key.'>'; } } return $xml; } -- http://www.php.net/manual/en/ref.array.php http://master.php.net/manage/user-notes.php?action=edit+21803 http://master.php.net/manage/user-notes.php?action=delete+21803 http://master.php.net/manage/user-notes.php?action=reject+21803

« previous php.notes (#31081) next »