Skip to content

Commit

Permalink
✨ (StrHelper): 字符串"true"/"false"转成boolean布尔型
Browse files Browse the repository at this point in the history
  • Loading branch information
Joycezhangw committed Apr 14, 2023
1 parent c2a4289 commit ed4c400
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/Helpers/StrHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static function getVoucherCode()

/**
* 生成订单号
* @param string $prefix 前缀
* @param string $prefix 前缀
* @return string
*/
public static function orderNo(string $prefix = '')
Expand Down Expand Up @@ -372,4 +372,16 @@ public static function isJson(string $str = '', $assoc = false)
}
return false;
}

/**
* 字符串"true"/"false"转成boolean布尔型
* @param $val
* @param bool $resultNull
* @return bool|mixed|null
*/
public static function isTrue($val, $resultNull = false)
{
$boolVal = (is_string($val) ? filter_var($val, FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE) : (bool)$val);
return ($boolVal === null && !$resultNull ? false : $boolVal);
}
}

0 comments on commit ed4c400

Please sign in to comment.