| Viewed 189 times

PHP pretty print array


PHP pretty print array

1 Answer
Mohammad Qandeel
Answered
2

Using print_r() you can print array in human-readable information  

when put it inside <pre></pre> the output will be exactly as written in the HTML file 

Example

<?php
echo'<pre>';
$array    = [1,2,3,'Qandeel','Academy'];
print_r($array);
echo'</pre>';
?>

Output

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
    [3] => Qandeel
    [4] => Academy
)

 

you can style <pre> in css 

pre {
 color: #000;
 background-color: #dff6df;
 padding: 10px;
 border-left: 4px solid #89bc89;
}