Jump to content

Recommended Posts

I don't know what you consider easier to read, but here is what you could do:

<?php
function display_array($array, $level=0)
{
foreach($array as $key => $value)
{
	$output .= str_repeat("\t",$level);
	if(!is_array($value))
	{
		$output .= "{$key} = {$value}\n";
	}
	else {
		$output .= "{$key} = Array:\n";
		$output .= display_array($value,$level+1);
	}
}

return $output;
}

$array = array(
	'hello'	=> 'world',
	'test' => array(
			'sub-thing' => 'hi',
			'new_array' => array(
					'test1',
					'test2',
					'test3',
					array(1,2,3,4),
				),
		),
	'bla' => 'php',
);
echo display_array($array);
?>

 

Output is:

hello = world
test = Array:
sub-thing = hi
new_array = Array:
	0 = test1
	1 = test2
	2 = test3
	3 = Array:
		0 = 1
		1 = 2
		2 = 3
		3 = 4
bla = php

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.