FAQ Database Discussion Community

Ternary operator when casting a variable

While writing is_numeric($var) ? (Int)$var : (String)$var;, I was wondering if it could be possible to move the ternary operator to the part where I cast the variable: echo (is_numeric($var) ? Int : String)$var; Not to my surprise, it didn't work: PHP Parse error: syntax error, unexpected '$var' (T_VARIABLE) Is...