Php - adding zeros

Hey there,

I need to add the appropriate number of zeros to a number depending on it’s length.

1 = 001
10 = 010
100 = 100

here are a couple failed attempts…


for ($i = 1; $i <= $maxtotal; $i++) { 
if (i>=100) {
${$i.'nam'} = stripslashes($_POST[$i.'_prod_name']);
}elseif (i<100 && i>=10) {
${$i.'nam'} = stripslashes($_POST['0'.$i.'_prod_name']);
} elseif (i<10) {
${$i.'nam'} = stripslashes($_POST['00'.$i.'_prod_name']);
}
}

or


$num_str = strlen(i);
if ($num_str <= 1) {
$setdigit = "00";
} else if ($num_str == 2) {
$setdigit = "0";
} else {
$setdigit = "";
}
${$i.'nam'} = stripslashes($_POST[$setdigit.$i.'_prod_name']);