Add MD_STD_IN::boolval()
This commit is contained in:
@@ -131,6 +131,20 @@ final class MD_STD_IN {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts an input value into a bool. Different from the default PHP way,
|
||||||
|
* the strings "false" and "False" are treated as negative.
|
||||||
|
*
|
||||||
|
* @param mixed $inputs Input data.
|
||||||
|
*
|
||||||
|
* @return boolean
|
||||||
|
*/
|
||||||
|
public static function boolval(mixed $inputs):bool {
|
||||||
|
|
||||||
|
if (is_string($inputs) && (strtolower($inputs) === "false")) return false;
|
||||||
|
return (bool)$inputs;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates an input array for all entries being strings. Unsets empty values.
|
* Validates an input array for all entries being strings. Unsets empty values.
|
||||||
* This is especially useful for parsed JSON.
|
* This is especially useful for parsed JSON.
|
||||||
|
|||||||
Reference in New Issue
Block a user