note 50028 added to function.print-r
| From: | php-general at lists dot php dot net | Date: | Wed, 16 Feb 2005 01:04:11 +0000 |
| Subject: | note 50028 added to function.print-r | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-85092@lists.php.net to get a copy of this message | ||
Here is a general function that recursively walks any array, and displays the contents in a nice
way:
<?php function walk($prefix, $array)
{
if (is_array($array)) foreach ($array as $key=>$val)
walk($prefix."[".$key."]",$val);
else echo "$prefix=$array;<BR>\n";
} ?>
For example:
<?php $test = array('a'=>'Aa',
'b'=>array('Bb'=>'Ccc'),
'd'=>array('Ee'=>array('Fff'=>'Gggg')) );
walk('$test', $test);
// Ouput:
/*
$test[a]=Aa;
$test[b][Bb]=Ccc;
$test[d][Ee][Fff]=Gggg;
*/
?>
----
Manual Page -- http://www.php.net/manual/en/function.print-r.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+50028
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+50028&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+50028&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+50028&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+50028&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+50028&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+50028&report=yes
Search -- http://master.php.net/manage/user-notes.php