Skip to content

Commit

Permalink
Changed indent variable to stop and added logic for an empty array
Browse files Browse the repository at this point in the history
  • Loading branch information
mkruzil committed Mar 2, 2013
1 parent 497ced6 commit a89b5ae
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
@@ -1,4 +1,4 @@
print_h
=======

Recursively prints human-readable information about a variable in HTML
Recursively prints human-readable information about a variable in HTML
2 changes: 1 addition & 1 deletion print_h.php
@@ -1 +1 @@
<?php/*print_hRecursively prints human-readable information about a variable in HTMLCopyright (c) 2013 Mike KruzilPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/function print_h($values, $indent_length = 0) { if (!is_array($values) || (is_array($values) && !$values)) { return; } else { ++$i; foreach($values as $name => $value) { if (is_array($value)) { print getIndent($indent_length); print "[{$name}]" . " => Array (<br />\n"; print_h($value, $indent_length); print getIndent($indent_length); print ")<br />"; } else { print getIndent($indent_length); print "[{$name}]" . " => " . $value . "<br />\n"; } } }}function getIndent($length) { $indent = ""; $i = 0; do { $indent .= "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"; } while (++$i < $length); return $indent;}?>
<?php/*print_hRecursively prints human-readable information about a variable in HTMLCopyright (c) 2013 Mike KruzilPermission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.*/<?phpfunction print_h($values, $stop = 0) { if (!is_array($values) || (is_array($values) && !$values)) { print "Array ()"; return; } else { ++$stop; $tab = getTab($stop); foreach($values as $name => $value) { if (is_array($value)) { print $tab . "[{$name}]" . " => Array (<br />\n"; print_h($value, $stop); print $tab . ")<br />"; } else { print $tab . "[{$name}]" . " => " . $value . "<br />\n"; } } }}function getTab($stop) { $tab = ""; $i = 0; do { $tab .= "&nbsp;&nbsp;&nbsp;&nbsp;"; } while (++$i < $stop); return $tab;}?>
Expand Down

0 comments on commit a89b5ae

Please sign in to comment.