note 54467 added to function.print-r

From: Date: Tue, 05 Jul 2005 13:56:11 +0000
Subject: note 54467 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-91473@lists.php.net to get a copy of this message
I have found the need to print out an array that can then be cut and paste into a php script to be assigned to a variable, so I made this function to put the ' on the keys, and appropriately handle booleans. <?php function print_array($thingy, $tab='') { switch(true) { case (is_array($thingy)): print "\n" . $tab . 'Array(' . "\n"; $newtab = $tab . "\t"; $ct = 1; foreach($thingy as $key => $value) { print $newtab . "'$key' => "; print_array($value, $newtab); if ($ct != count($thingy)) print ',' . "\n"; ++$ct; } print "\n" . $tab . ')'; break; case (is_numeric($thingy)): print $thingy; break; case (is_bool($thingy)): if ($thingy) print 'TRUE'; else print 'FALSE'; break; default: print "'$thingy'"; } } ?> ---- Manual Page -- http://www.php.net/manual/en/function.print-r.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+54467 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+54467&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+54467&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+54467&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+54467&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+54467&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+54467&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+54467&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#91473) next »