Re: Displaying full array contents

From: Date: Fri, 27 Sep 2002 01:46:00 +0000
Subject: Re: Displaying full array contents
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-117802@lists.php.net to get a copy of this message
It's a slightly different format, but print_r($array) recursively echo the contents of an array ina readable format? http://php.net/print_r Why reinvent the wheel, unless you need that specific format. HTH Justin on 27/09/02 3:50 AM, Brad Harriger (bradharriger@clarionhospital.org) wrote: > I'm trying to write a function that will display the full contents of an > array. If one of the keys contains a value that is an array, the full > array (all indices) should be shown. > > As an example, given the following definitions: > > $Arr1[1] = "Apple"; > $Arr1[2] = "Banana"; > $Arr1[3] = $Arr2[]; > $Arr2[1] = "Carrot"; > $Arr2[2] = $Arr3[]; > $Arr3[1] = "Orange"; > $Arr3[2] = "Peach"; > > > the output should be: > > Arr1:1:Apple > Arr1:2:Banana > Arr1:3:Arr2[] > Arr1:3:Arr2:1:Carrot > Arr1:3:Arr2:2:Arr3[] > Arr1:3:Arr2:2:Arr3:1:Orange > Arr1:3:Arr2:2:Arr3:2:Peach > > The closest I've come is: > > while (current($myArr)) > { > if(is_array(current($myArr))) > { > $arrKey = key(current($myArr)); > echo "Array "; > echo "&nbsp=&nbsp"; > $baseArray = key($myArr); > echo key($myArr); > echo "<BR>\n"; > walkArray(current($myArr)); > } > else > { > $arrKey = key($myArr); > if ($baseArray != "") > { > echo $baseArray; > echo ":"; > } > echo $arrKey; > echo "&nbsp=&nbsp"; > echo current($myArr); > echo "<BR>\n"; > } > next($myArr); > } > > This code only echoes one dimension of a multi-dimension array. I can't > find a way to reliably store more than that. Any suggestions? > > Thanks in advance, > > Brad >

« previous php.general (#117802) next »