mirror of
https://github.com/Piwigo/Piwigo.git
synced 2025-05-12 11:26:08 +03:00
better get_boolean function: able to detect "0" as false, (bool)false as false
and (int)0 as false. git-svn-id: http://piwigo.org/svn/trunk@12752 68402e56-0260-453c-a942-63ccdbb3a9ee
This commit is contained in:
parent
1ea0155ad7
commit
1c84017d23
1 changed files with 11 additions and 8 deletions
|
@ -634,17 +634,20 @@ function get_enums($table, $field)
|
|||
return $options;
|
||||
}
|
||||
|
||||
// get_boolean transforms a string to a boolean value. If the string is
|
||||
// "false" (case insensitive), then the boolean value false is returned. In
|
||||
// any other case, true is returned.
|
||||
function get_boolean( $string )
|
||||
/**
|
||||
* Smartly checks if a variable is equivalent to true or false
|
||||
*
|
||||
* @param mixed input
|
||||
* @return bool
|
||||
*/
|
||||
function get_boolean($input)
|
||||
{
|
||||
$boolean = true;
|
||||
if ( 'false' == strtolower($string) )
|
||||
if ('false' === strtolower($input))
|
||||
{
|
||||
$boolean = false;
|
||||
return false;
|
||||
}
|
||||
return $boolean;
|
||||
|
||||
return (bool)$input;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue