Advertisement
nicolaslagios

PHP Variable Testing Function

Oct 6th, 2023 (edited)
964
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.57 KB | Source Code | 0 0
  1. //Just use this function as testing($your-variable,"php"); for php or testing($your-variable,"js"); for console printing in dev tools
  2. function testing($variable,$type = "php"){
  3.     if ($type == "js") {
  4.         if (!is_array($variable)) {
  5.             echo "<script>console.log('".$variable."');</script>";
  6.         } else {
  7.             echo "<script>console.log(JSON.stringify(".json_encode($variable).", null, 2));</script>";
  8.         }
  9.     } else {
  10.         if (!is_array($variable)) {
  11.             echo "<br>Function Results: ".$variable."<br>";
  12.         } else {
  13.             echo "<pre>";
  14.             print_r($variable);
  15.             echo "</pre>";
  16.         }
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement