note 81050 added to function.array
| From: | sebasg37 at gmail dot com | Date: | Tue, 12 Feb 2008 19:32:01 +0000 |
| Subject: | note 81050 added to function.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-136072@lists.php.net to get a copy of this message | ||
Recursive function similar to print_r for describing anidated arrays in html <ol>. Maybe
it's useful for someone.
<?php
function describeAnidatedArray($array)
{
$buf = '';
foreach($array as $key => $value)
{
if(is_array($value))
{
$buf .= '<ol>' . describeAnidatedArray($value) . '</ol>';
}
else
$buf .= "<li>$value</li>";
}
return $buf;
}
// Example:
$array = array("a", "b", "c", array("1", "2",
array("A", "B")), array("3", "4"), "d");
echo describeAnidatedArray($array);
?>
output:
# a
# b
# c
1. 1
2. 2
1. A
2. B
1. 3
2. 4
# d
----
Server IP: 190.2.55.3
Probable Submitter: 200.123.133.161
----
Manual Page -- http://www.php.net/manual/en/function.array.php
Edit -- https://master.php.net/note/edit/81050
Del: integrated -- https://master.php.net/note/delete/81050/integrated
Del: useless -- https://master.php.net/note/delete/81050/useless
Del: bad code -- https://master.php.net/note/delete/81050/bad+code
Del: spam -- https://master.php.net/note/delete/81050/spam
Del: non-english -- https://master.php.net/note/delete/81050/non-english
Del: in docs -- https://master.php.net/note/delete/81050/in+docs
Del: other reasons-- https://master.php.net/note/delete/81050
Reject -- https://master.php.net/note/reject/81050
Search -- https://master.php.net/manage/user-notes.php