In this tutorial we will learn How To Print array line by line in PHP, So that the contents of array are more readable. For this we can use print_r() function inside the HTML pre tag. We can use echo statement to output the pre tag.
Table of Contents
PHP echo Statement
PHP echo statement is used to output or print data on screen.
<?php
echo "HowToCodeSchool.com"; // Output HowToCodeSchool.com
?>
PHP print_r() function
PHP print_r() function prints or outputs the variable data or array contents on the screen.
print_r() function is used to check the keys and values of array.
<?php
$array = array("HTML", "CSS", "JavaScript" , "PHP");
echo '<pre>'; print_r($array); echo '</pre>';
?>
The above code will output both keys and values of the array line by line. This is very helpful for arrays with more values.