Another Cast To Int¶
<?php
$a = '2';
$b = +$a;
var_dump($b);
?>
Another way to cast a value to int, besides the obvious (int) operator and the classic + 0, is to use the unary operator + operator on a variable: it add a sign operation on the variable, and the + sign is invariant: yet, the content of the variable is turned into an integer.
See Also¶
Another cast to int [Try me]
PHP Features¶
Last updated: 14 July 2026