note 55780 added to function.print-r

From: Date: Fri, 12 Aug 2005 21:34:53 +0000
Subject: note 55780 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-93526@lists.php.net to get a copy of this message
Here is a nicer print_r function: <?php // Prints the contents of an array, nicely function print_array($array, $spaces='0', $space_char="\t", $font_1="4A2885", $font_2="00A54E") { // Is $array an array? if(!is_array($array)) { // No, print out a nice error message echo 'Opps! The variable given is not an array<br />'; } else { // Yes, continue // Loop through foreach($array as $key=>$value) { $spaces_counter = '0'; while($spaces > $spaces_counter) { echo "$space_char"; $spaces_counter++; } // Print the contents echo '<font color="#'.$font_1.'">'.$key.'</font> = <font color="#'.$font_2.'">'.$value.'</font><br>'; // Is the $key a array? if(is_array($value)) { // Yes, call this function $new_spaces = $spaces + 1; print_array($value, $new_spaces, $space_char); } } } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.print-r.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55780 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55780&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55780&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55780&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55780&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55780&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55780&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55780&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#93526) next »