luya\helpers\StringHelper::typeCast PHP Method

typeCast() public static method

Arrays will passed to to the {{luya\helpers\ArrayHelper::typeCast}} class.
public static typeCast ( mixed $string ) : mixed
$string mixed The input string to type cast. Arrays will be passted to {{luya\helpers\ArrayHelper::typeCast}}.
return mixed The new type casted value, if the input is an array the output is the typecasted array.
    public static function typeCast($string)
    {
        if (is_numeric($string)) {
            if (is_float($string)) {
                return (double) $string;
            } else {
                return (int) $string;
            }
        } elseif (is_array($string)) {
            return ArrayHelper::typeCast($string);
        }
        return $string;
    }

Usage Example

Ejemplo n.º 1
0
 public function testStringTypeCast()
 {
     $this->assertSame(0, StringHelper::typeCast("0"));
     $this->assertSame(1, StringHelper::typeCast('1'));
     $this->assertSame('string', StringHelper::typeCast('string'));
     $this->assertSame([1 => 'bar'], StringHelper::typeCast(['1' => 'bar']));
 }
All Usage Examples Of luya\helpers\StringHelper::typeCast