note 67923 deleted from ref.array by levim
| From: | levim@php.net | Date: | Tue, 06 May 2014 22:00:33 +0000 |
| Subject: | note 67923 deleted from ref.array by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-199438@lists.php.net to get a copy of this message | ||
Note Submitter: kroczu at interia dot pl
----
<?
//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>
*/
?>