Skip to content
This repository was archived by the owner on Nov 18, 2025. It is now read-only.

Commit 87d5dee

Browse files
committed
✨ add is_blank() function
Signed-off-by: otengkwame <[email protected]>
1 parent eaaf840 commit 87d5dee

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

framework/core/Common.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,41 @@ function is($key, $value = null)
180180

181181
// ------------------------------------------------------------------------
182182

183+
if ( ! function_exists('is_blank'))
184+
{
185+
/**
186+
* Determines if the given value is "blank"
187+
*
188+
* From https://amitmerchant.com/cool-helper-function-to-check-anything-blank-php
189+
*
190+
* @param mixed $value
191+
* @return bool
192+
*/
193+
function is_blank($value)
194+
{
195+
if (is_null($value)) {
196+
return true;
197+
}
198+
199+
if (is_string($value)) {
200+
return trim($value) === '';
201+
}
202+
203+
if (is_numeric($value) || is_bool($value)) {
204+
return false;
205+
}
206+
207+
if ($value instanceof Countable) {
208+
return count($value) === 0;
209+
}
210+
211+
return empty($value);
212+
}
213+
214+
}
215+
216+
// ------------------------------------------------------------------------
217+
183218
if ( ! function_exists('import'))
184219
{
185220
/**

0 commit comments

Comments
 (0)