note 21803 deleted from ref.array by maxim

From: Date: Tue, 12 Nov 2002 16:06:42 +0000
Subject: note 21803 deleted from ref.array by maxim
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-39384@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; }

« previous php.notes (#39384) next »