Last active
August 29, 2015 14:01
-
-
Save daithi-coombes/10949948c5bbc7b5afd5 to your computer and use it in GitHub Desktop.
print a html formated version of print_r including variable name
This file contains hidden or 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 | |
| /** | |
| * Print a datatype structure parsed for browser | |
| * @param mixed $ar The datatype | |
| */ | |
| if( !function_exists('ar_print') ){ | |
| function ar_print( &$var ){ | |
| //get variable name | |
| foreach ($GLOBALS as $k => $v) | |
| $global_vars[$k] = $v; | |
| $saved_var = $var; | |
| $var = !$var; | |
| $diff = array_udiff_uassoc($global_vars, $GLOBALS, "ar_print_udiff_callback", "ar_print_udiff_callback"); | |
| $name = key($diff); | |
| $var = $saved_var; | |
| //end get variable name | |
| //print stdout | |
| print '<pre class="ar-print">'."\n"; | |
| print '$'.$name . " → "; | |
| print_r($var); | |
| print '</pre>'; | |
| } | |
| } | |
| if( !function_exists('ar_print_udiff_callback') ){ | |
| function ar_print_udiff_callback($a, $b){ | |
| //bug in php 5.2 - can't test recursive objects, so skip all | |
| //@link http://stackoverflow.com/questions/3834791/fatal-error-nesting-level-too-deep-recursive-dependency | |
| if( PHP_VERSION_ID<=50217 ) | |
| return 0; | |
| if( $a==$b ) | |
| return 0; | |
| return ($a > $b) ? 1 : -1; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment