|
Posted by Toby A Inkster on 03/24/07 00:05
lawpoop wrote:
> function show_array( $array, $level = 0, $counter = 0 ) {
>
> $count = count($array);
>
>
> foreach ( $array as $key => $value ) {
>
> if ( is_array($value) ) {
>
> $level++;
>
> $counter = 0;
>
> show_array( $value, $level, $counter );
>
> } else {
>
> $counter++;
>
> for ( $i = 0; $i <= $level; $i++ ) {
> echo " - ";
> }
>
> echo "$value\n";
>
> if ( $counter == $count ) {
>
> $level--;
>
> $counter = 0;
> }
> }
> }
> }
You've overcomplicated things. You don't need all these counters and stuff.
function show_array ($array, $indent='')
{
foreach ($array as $value)
{
if (is_array($value))
show_array($value, $indent.' - ');
else
echo $indent.$value."\n";
}
}
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
Geek of ~ HTML/SQL/Perl/PHP/Python*/Apache/Linux
* = I'm getting there!
Navigation:
[Reply to this message]
|