Changeset 12752


Ignore:
Timestamp:
Dec 16, 2011, 9:57:55 PM (9 years ago)
Author:
plg
Message:

better get_boolean function: able to detect "0" as false, (bool)false as false
and (int)0 as false.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/dblayer/functions_mysql.inc.php

    r12748 r12752  
    635635}
    636636
    637 // get_boolean transforms a string to a boolean value. If the string is
    638 // "false" (case insensitive), then the boolean value false is returned. In
    639 // any other case, true is returned.
    640 function get_boolean( $string )
    641 {
    642   $boolean = true;
    643   if ( 'false' == strtolower($string) )
    644   {
    645     $boolean = false;
    646   }
    647   return $boolean;
     637/**
     638 * Smartly checks if a variable is equivalent to true or false
     639 *
     640 * @param mixed input
     641 * @return bool
     642 */
     643function get_boolean($input)
     644{
     645  if ('false' === strtolower($input))
     646  {
     647    return false;
     648  }
     649
     650  return (bool)$input;
    648651}
    649652
Note: See TracChangeset for help on using the changeset viewer.