I see manual of php.net and see sortie of examples, when use var_dump and others commands for see examples.
All examples sort with pre style.
But on my own server I see same examples on only one line
var_dump($a);
On manual see->
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
array(3) {
[0]=>
string(1) "a"
[1]=>
string(1) "b"
[2]=>
string(1) "c"
}
}
On my server I see:
array(3) {[0]=>int(1) [1]=>int(2) [2]=>array(3) {[0]=>string(1) "a" [1]=>string(1) "b" [2]=>string(1) "c"}}
I think this is a runtime option, which I can change, but I'm not sure. So how can I get the output in the same format as in the manual?
You are probably looking for the pre
tag, which will give you a nice formatted output. Just print it before you use var_dump();
, e.g.
echo "<pre>";
var_dump($arr);
echo "</pre>";
Example input/output:
$arr = [1, 2, 3];
with pre
tag:
array(3) {
[0]=>
int(1)
[1]=>
int(2)
[2]=>
int(3)
}
without pre
tag:
array(3) { [0]=> int(1) [1]=> int(2) [2]=> int(3) }
I crated this function for this case.
function echo_array($array,$name = '')
{
$debug = debug_backtrace();
$file = $debug[0]['file'];
$line = $debug[0]['line'];
$array = "<pre>".print_r($array,true)."</pre>";
?>
<table cellpadding="0" cellspacing="0" width="100%" style="background-color:white;">
<tr>
<td align="left">
<fieldset>
<legend>
<?=$name?> in: <?=$file?>:<?=$line?>
</legend>
<?=$array?>
</fieldset>
</td>
</tr>
</table>
<?
}
With print_r()
can you pass the array and the second parameter says that it should be return instead of printed out.
I use the debug information to get where this function was called because sometimes I have to many of them, that it can get confusing. You can also set a name for it to determine what was echoed ;)