PHP function of the day: print_r()

For day 17 of 21 in the “PHP Function of the day” series, I’m going to look at print_r(). We have already used print_r() on days 4, 5, and 11.

Let’s take a look.

<?php

$num = 123;

$str = “Joe”;

$arr = array(1, 2, 3);

print_r($num);

print_r($str);

print_r($arr);

?>

 

See the output

 

As you can see, the function just dumps the value to the page.  The reason why it was used in the array_diff(), array(), and gettimeofday() posts is because (unlike echo()) it can handle more than just strings and numeric values.

Leave a Reply

Your email address will not be published. Required fields are marked *