The following is my code,
$da =01;
$cal_sunday = $da + 7;
echo $cal_sunday;
the above calculation return the output as '8'.. i need the output as '08'... help..
The following is my code,
$da =01;
$cal_sunday = $da + 7;
echo $cal_sunday;
the above calculation return the output as '8'.. i need the output as '08'... help..
Have a look at the sprintf function
Your calculation produces and integer but you require a string.
Use sprintf to return the string in the format you need.
$da = 1;
$cal_sunday = $da + 7;
printf('%02s', $cal_sunday);
printf()
and sprintf()
work similarly, except the first does a direct output, while the later returns the value so it can be assigned to another variable.
$da = 1;
$cal_sunday = sprintf('%02s', $da + 7);
echo $cal_sunday;