PHP- print_r() Function

The print_r() function is a function which can be used to show the contents, or make-up, of an array.

For example, we create the following array in PHP:

If we just used the following line to show display the array, it would not work:

This would produce the following output in PHP:

Array

An array is a special object in PHP. A programmer cannot print out the contents of an array,
as shown above, simply with the echo or print function.

However, applying the print_r() function, can be used for showing all of the contents of an array.

The above line of code would yield the following in PHP:

Array ( [0] => item1 [1] => item2 [2] => item3 [3] => item4 )