Best way to debug an array using PHP Best way to debug an array using PHP arrays arrays

Best way to debug an array using PHP


Every PHP developer should have a function for this. My function is below:

function r($var){    echo '<pre>';    print_r($var);    echo '</pre>';}

To nicely print data, just call r($data);. If you want more detail, you could use this function:

function d($var){    echo '<pre>';    var_dump($var);    echo '</pre>';}


Everyone suggests print_r which is in core and works really well.But when it comes to view a large array, print_r() drives me nuts narrowing down the output.

Give a try to krumo.It nicely prints the array with visual formatting, click-expand and it also gives you the exact array key call that you can simply copy and paste.

<?php krumo($my_array);?>

Itroubs mentioned Kint as a better alternative to Krumo. (Thanks ITroubs!)