Can PHP’s print_r function somehow print words like NULL and false?

  arrays, boolean, null, php

Unlike var_dump or var_export the function print_r seems to display blanks instead of words like NULL and false:

<?php
$arr = array('one' => true, 'zero' => false, 'null' => null, 'recursive' => array(1=>array(2=>3)));
echo '<pre>' . print_r($arr, true) . '</pre>'; // Array
echo '<pre>' . var_export($arr, true) . '</pre>'; // String => gettype(var_export($arr)); returns string
?>

Array
(
    [one] => 1
    [zero] => 
    [null] => 
    [recursive] => Array
        (
            [1] => Array
                (
                    [2] => 3
                )
        )
)

array (
  'one' => true,
  'zero' => false,
  'null' => NULL,
  'recursive' => 
  array (
    1 => 
    array (
      2 => 3,
    ),
  ),
)

var_dump/export aren’t nearly as nicely readable as print_r, so can anything be done to show such words in print_r?

Source: Ask PHP

LEAVE A COMMENT