<?php
$str = "02";
$int = 1;
$result = $str-$int;
echo $result // 1
?>
But I need result = 01
Don't tell me "0".$str-$int;
<?php
$str = "02";
$int = 1;
printf('%02d', $str-$int);
or
<?php
$str = "02";
$int = 1;
$result = sprintf('%02d', $str-$int);
// do something with $result here
try
printf("%02d",$str-$int);
The explanation of the numerous formatting possibilities of printf are explained in the sprintf docs
<?
$str = "02";
$int = 1;
echo sprintf("%02d", (int)$str - $int);
?>
Use str_pad() where you set it to pad the left with 0's until the length of string is 2 chars.
echo str_pad($str - $int, 2, '0', STR_PAD_LEFT);