/** * Cast a value to float. * * @static * * @param mixed $value Value to cast. * @param bool $array2null (Optional) Whether to return null for an array or to cast the * individual values within the array to the chosen type. * @param bool $allow_empty (Optional) Whether to allow empty arrays. Only has effect * when $array2null = false. * * @return float|array|null */ function _float($value, $array2null = true, $allow_empty = true) { if (is_float($value)) { return $value; } else { if ($array2null === false && is_array($value)) { return CastToType::recurse($value, '_float', $allow_empty); } else { if (is_scalar($value) && (is_numeric(trim($value)) && floatval($value) == trim($value))) { return floatval($value); } else { if (is_object($value) && get_class($value) === 'SplFloat') { if ((double) $value == $value) { return (double) $value; } else { return null; } } else { if (is_object($value) && (get_class($value) === 'SplBool' || get_class($value) === 'SplInt' || get_class($value) === 'SplString')) { return CastToType::spl_helper($value, '_float', $array2null, $allow_empty); } } } } } return null; }