From f107addc0cca920755b0dbd35d33b049060d6b7d Mon Sep 17 00:00:00 2001 From: Sajjad Hossain Shohag <63788037+sajjadhossainshohagbd@users.noreply.github.com> Date: Thu, 28 Mar 2024 15:07:37 +0000 Subject: [PATCH] Added dd_if helper --- Resources/functions/dump.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Resources/functions/dump.php b/Resources/functions/dump.php index f2ff74c0..d39af21d 100644 --- a/Resources/functions/dump.php +++ b/Resources/functions/dump.php @@ -60,3 +60,22 @@ function dd(mixed ...$vars): never exit(1); } } + +if(!function_exists('dd_if')){ + function dd_if($condition,... $vars): mixed + { + if(!$condition){ + return null; + } + + if (array_key_exists(0, $vars) && 1 === count($vars)) { + VarDumper::dump($vars[0]); + } else { + foreach ($vars as $k => $v) { + VarDumper::dump($v, is_int($k) ? 1 + $k : $k); + } + } + + exit(1); + } +} \ No newline at end of file