note 55780 deleted from function.print-r by derick

From: Date: Thu, 27 Oct 2005 10:16:31 +0000
Subject: note 55780 deleted from function.print-r by derick
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-97676@lists.php.net to get a copy of this message
Note Submitter: KingCoder ---- 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); } } } } ?>

« previous php.notes (#97676) next »