How to display a single digit number as 2 digit

I am trying to do a quiz. Having some 20 questions. When displaying answer, when th mark is below 10 means it must display in 2 digits… (eg) 01, 05, 08… etc. Please help… :frowning: :frowning: :frowning: :frowning: :frowning: :frowning:

[php]

<?php $answer1= $_POST['answerOne']; $answer2= $_POST['answerTwo']; $answer3= $_POST['answerThree']; $answer4= $_POST['answerFour']; $answer5= $_POST['answerFive']; $answer6= $_POST['answerSix']; $answer7= $_POST['answerSeven']; $answer8= $_POST['answerEight']; $answer9= $_POST['answerNine']; $answer10= $_POST['answerTen']; $answer11= $_POST['answer11']; $answer12= $_POST['answer12']; $answer13= $_POST['answer13']; $answer14= $_POST['answer14']; $answer15= $_POST['answer15']; $answer16= $_POST['answer16']; $answer17= $_POST['answer17']; $answer18= $_POST['answer18']; $answer19= $_POST['answer19']; $answer20= $_POST['answer20']; $score = 0; if ($answer1 == "A"){$score++;} if ($answer2 == "B"){$score++;} if ($answer3 == "C"){$score++;} if ($answer4 == "A"){$score++;} if ($answer5 == "B"){$score++;} if ($answer6 == "C"){$score++;} if ($answer7 == "A"){$score++;} if ($answer8 == "B"){$score++;} if ($answer9 == "C"){$score++;} if ($answer10 == "A"){$score++;} if ($answer11 == "B"){$score++;} if ($answer12 == "C"){$score++;} if ($answer13 == "A"){$score++;} if ($answer14 == "B"){$score++;} if ($answer15 == "C"){$score++;} if ($answer16 == "A"){$score++;} if ($answer17 == "B"){$score++;} if ($answer18 == "C"){$score++;} if ($answer19 == "A"){$score++;} if ($answer20 == "B"){$score++;} echo "
$score
"; ?>

[/php]

[php]<?php
for ($score=0; $score <= 20; $score++)
{
if (strlen($score) < 2) {

echo "0" . $score . "<br>";

} else {

echo $score . "<br>";

}
}[/php]

[php]str_pad($score, 2, ‘0’, STR_PAD_LEFT)[/php]

Dude! its not working… i just used it before the echo score line… correct me if i am wrong… :frowning:

[php]echo “

” . str_pad($score, 2, ‘0’, STR_PAD_LEFT) . “
”;[/php]

Dude! fantastic! it worked… thank you so much… thanks a lot… ;D ;D ;D

Sponsor our Newsletter | Privacy Policy | Terms of Service