note 107298 added to function.print-r

From: Date: Sat, 28 Jan 2012 15:10:33 +0000
Subject: note 107298 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-185777@lists.php.net to get a copy of this message
print_r is used for debug purposes. Yet I had some classes where I just wanted the values coming out of the database, not all the other crap. thus i wrote the following function. If your class has an toArray function, that one will be called otherwise it will return the object as is. print_neat_classes_r is the function that should be called! print_neat_classes_r($array, $return=false){ return print_r(self::neat_class_print_r($array), $return); } function do_print_r($array, $return=false){ if(is_object($array) && method_exists($array, 'toArray')){ return $array->toArray(); }else if(is_array($array)){ foreach($array as $key=>$obj){ $array[$key] = self::do_print_r($obj, $return); } return $array; }else{ return $array; } } ---- Server IP: 91.199.167.223 Probable Submitter: 82.157.123.135 ---- Manual Page -- http://www.php.net/manual/en/function.print-r.php Edit -- https://master.php.net/note/edit/107298 Del: integrated -- https://master.php.net/note/delete/107298/integrated Del: useless -- https://master.php.net/note/delete/107298/useless Del: bad code -- https://master.php.net/note/delete/107298/bad+code Del: spam -- https://master.php.net/note/delete/107298/spam Del: non-english -- https://master.php.net/note/delete/107298/non-english Del: in docs -- https://master.php.net/note/delete/107298/in+docs Del: other reasons-- https://master.php.net/note/delete/107298 Reject -- https://master.php.net/note/reject/107298 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#185777) next »