Numeric Separators Inside A String?¶
<?php
echo 1_2_3;
$a = '1_2_3';
// warning: a non-numeric value encountered
echo $a + 0; // 1
echo (int) $a; // 1
$int = eval("return $a;");
Since PHP 7.4, there are numeric separators, to make integers more readable.
They are only for hard-coded literals, so what do you do if you have stored them in a string?
The solution is to rely on eval(), with a trick : $int = eval('return '.$a.';');. return is important to return the value that was generated by the code.
Another option is to remove the underscore _ chars, and cast the value to int.
See Also¶
numeric separator in strings [Try me]
PHP Features¶
Last updated: 16 July 2026