Skip to content

Commit ed4c400

Browse files
committed
✨ (StrHelper): 字符串"true"/"false"转成boolean布尔型
1 parent c2a4289 commit ed4c400

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/Helpers/StrHelper.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ public static function getVoucherCode()
219219

220220
/**
221221
* 生成订单号
222-
* @param string $prefix 前缀
222+
* @param string $prefix 前缀
223223
* @return string
224224
*/
225225
public static function orderNo(string $prefix = '')
@@ -372,4 +372,16 @@ public static function isJson(string $str = '', $assoc = false)
372372
}
373373
return false;
374374
}
375+
376+
/**
377+
* 字符串"true"/"false"转成boolean布尔型
378+
* @param $val
379+
* @param bool $resultNull
380+
* @return bool|mixed|null
381+
*/
382+
public static function isTrue($val, $resultNull = false)
383+
{
384+
$boolVal = (is_string($val) ? filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : (bool)$val);
385+
return ($boolVal === null && !$resultNull ? false : $boolVal);
386+
}
375387
}

0 commit comments

Comments
 (0)