Skip to content

Instantly share code, notes, and snippets.

@Abhinav1217
Last active December 15, 2015 21:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Abhinav1217/5326156 to your computer and use it in GitHub Desktop.
Save Abhinav1217/5326156 to your computer and use it in GitHub Desktop.
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