W3docs

How to write own DD() function same as laravel?

To create your own version of the Laravel DD() function, you can create a new function in your codebase and have it take in any number of arguments.

To create your own version of the Laravel DD() function, you can define a new function in your codebase that accepts any number of arguments using PHP's variadic syntax. Inside the function, you can iterate over the arguments and use var_dump() or print_r() to output their values, then call exit(1) to stop script execution, matching Laravel's behavior. Here's an example:

Example of creating your own version of the Laravel DD() function

<?php

function DD(...$args)
{
  foreach ($args as $arg) {
    var_dump($arg);
  }
  exit(1);
}

<div class="alert alert-info flex not-prose"> Watch a course <span class="hidden md:block">Watch a video course </span> Learn object oriented PHP</div>

You can call this function with any number of arguments, just like the Laravel DD() function.

Example of calling your own version of the Laravel DD() function

<?php

function DD(...$args)
{
  foreach ($args as $arg) {
    var_dump($arg);
  }
  exit(1);
}

DD("Hello World!", 123, ["a", "b", "c"]);