How To Print an Array in PHP Print

  • 82

Printing an array can be quite useful when debugging your PHP code and luckily PHP makes the task simple.

The print_r(array) function takes any array as an argument and iterates through it, printing the results to standard out as it goes.

 

For example:

<?php
$myArray = array("One", "Two", "Three");
print_r($myArray);
?>

The above code will display the contents of $myArray.


Was this answer helpful?

« Back