Last active
December 15, 2015 21:29
-
-
Save Abhinav1217/5326156 to your computer and use it in GitHub Desktop.
A Better alternative to PHP print_r() function.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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