note 67923 added to ref.array

From: Date: Thu, 06 Jul 2006 13:53:58 +0000
Subject: note 67923 added to ref.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-114511@lists.php.net to get a copy of this message
<? //A little function to convert array to simle xml: function array_xml($array, $num_prefix = "num_") { if(!is_array($array)) // text { return $array; } else { foreach($array as $key=>$val) // subnode { $key = (is_numeric($key)? $num_prefix.$key : $key); $return.="<".$key.">".array_xml($val, $num_prefix)."</".$key.">"; } } return $return; } //example: $array[0][0] = 1; $array[0]['test'] = "test"; $array['test1']['test2'] = "test"; $array['test'][0] = "test"; $array['test'][1]['test_x'] = $array; print_r($array); print"<xml>"; print array_xml($array); print"</xml>"; /* print_r($array) previev: Array ( [0] => Array ( [0] => 1 [test] => test ) [test1] => Array ( [test2] => test ) [test] => Array ( [0] => test [1] => Array ( [test_x] => Array ( [0] => Array ( [0] => 1 [test] => test ) [test1] => Array ( [test2] => test ) [test] => Array ( [0] => test ) ) ) ) ) result xml in firefox preview: -<xml> - <num_0> <num_0>1</num_0> <test>test</test> </num_0> - <test1> <test2>test</test2> </test1> - <test> <num_0>test</num_0> - <num_1> - <test_x> - <num_0> <num_0>1</num_0> <test>test</test> </num_0> - <test1> <test2>test</test2> </test1> - <test> <num_0>test</num_0> </test> </test_x> </num_1> </test> </xml> */ ?> ---- Server IP: 195.136.184.34 Probable Submitter: 83.13.39.19 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/ref.array.php Edit -- http://master.php.net/note/edit/67923 Del: integrated -- http://master.php.net/note/delete/67923/integrated Del: useless -- http://master.php.net/note/delete/67923/useless Del: bad code -- http://master.php.net/note/delete/67923/bad+code Del: spam -- http://master.php.net/note/delete/67923/spam Del: non-english -- http://master.php.net/note/delete/67923/non-english Del: in docs -- http://master.php.net/note/delete/67923/in+docs Del: other reasons-- http://master.php.net/note/delete/67923 Reject -- http://master.php.net/note/reject/67923 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#114511) next »