Mahdi.Pishguy Mahdi.Pishguy - 7 months ago 35
PHP Question

PHP remove last zero from integer by substr

in php i get some values from database as integer, now i want to remove last zero from

20000000
integer, but me below code doesnt work.

$payerd_amount = 20000000;
$payerd_amount = substr((string)$payerd_amount,1,strlen((string)$payerd_amount) -1);


how to do this action? my code seems correct but after substring i get this result:

000

Answer

If all you want to do is remove the last zero, just divide by 10

   $payerd_amount = $payerd_amount / 10;

This works, too:

   $payerd_amount = substr($payerd_amount, 0, -1);
Comments