note 73436 added to function.print-r

From: Date: Fri, 23 Feb 2007 06:47:40 +0000
Subject: note 73436 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-123735@lists.php.net to get a copy of this message
For those of you needing to print an array within a buffer callback function, I've created this quick function. It simply returns the array as a readable string rather than printing it. You can even choose whether to return it in normal text-mode or HTML. It's recursive, so multi-dimensial arrays are supported. I hope someone finds this useful! <?php function return_array($array, $html = false, $level = 0) { $space = $html ? "&nbsp;" : " "; $newline = $html ? "<br />" : "\n"; for ($i = 1; $i <= 6; $i++) { $spaces .= $space; } $tabs = $spaces; for ($i = 1; $i <= $level; $i++) { $tabs .= $spaces; } $output = "Array" . $newline . $newline; foreach($array as $key => $value) { if (is_array($value)) { $level++; $value = return_array($value, $html, $level); $level--; } $output .= $tabs . "[" . $key . "] => " . $value . $newline; } return $output; } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 74.102.141.219 ---- Manual Page -- http://www.php.net/manual/en/function.print-r.php Edit -- https://master.php.net/note/edit/73436 Del: integrated -- https://master.php.net/note/delete/73436/integrated Del: useless -- https://master.php.net/note/delete/73436/useless Del: bad code -- https://master.php.net/note/delete/73436/bad+code Del: spam -- https://master.php.net/note/delete/73436/spam Del: non-english -- https://master.php.net/note/delete/73436/non-english Del: in docs -- https://master.php.net/note/delete/73436/in+docs Del: other reasons-- https://master.php.net/note/delete/73436 Reject -- https://master.php.net/note/reject/73436 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#123735) next »