Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A Better alternative to PHP print_r() function.
<?php
/**
* This function is an alternative to default PHP print_r() function.
* it displays the output as a recursive list items with highlighted key and values.
*/
function pp($arr){
$retStr = '<ul>';
if (is_array($arr)){
foreach ($arr as $key=>$val){
if (is_array($val)){
$retStr .= '<li><span style="color:red;">' . $key . '</span><b> => </b><span style="color:blue;">' . pp($val) . '</span></li>';
}else{
$retStr .= '<li><span style="color:red;">' . $key . '</span><b> => </b><span style="color:blue;">' . $val . '</span></li>';
}
}
}
$retStr .= '</ul>';
return $retStr;
}
echo pp($_REQUEST);
/**
* Of course if you need something more stable for some bigger project, My personal favorite is kurmo "http://krumo.kaloyan.info/".
*/
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment