dimipan80

Dump Variable

Dec 2nd, 2014
228
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.50 KB | None | 0 0
  1. /* Write a PHP script DumpVariable.php that declares a variable. If the variable is numeric, print it by
  2. the built-in function var_dump(). If the variable is not numeric, print its type at the input. */
  3.  
  4. <?php
  5. function dumpVariable($var) {
  6.     if (is_numeric($var)) {
  7.         var_dump($var);
  8.     } else {
  9.         echo gettype($var)."\n";
  10.     }
  11. }
  12.  
  13. dumpVariable('hello');
  14. dumpVariable(15);
  15. dumpVariable(1.234);
  16. dumpVariable(array(1,2,3));
  17. dumpVariable((object)[2,34]);
  18. dumpVariable(false);
  19. dumpVariable('true');
  20. ?>
Add Comment
Please, Sign In to add comment