Page 1 of 1

1 digit numbers

Posted: Tue Jun 01, 2004 2:30 pm
by cgroup
I'm having trouble getting single digit numbers to be 1 digit. This is what I have:

Code: Select all

<?php
$num_right = 0;
if (expression) {
$num_right .= $num_right + 1;
} elseif (expression) {
$num_right .= $num_right + 1;
}
?>
And I get:

Code: Select all

01
or
02
I'd like the code to generate 1 digit numbers like 1 instead of 01. Any suggetions? :D

Posted: Tue Jun 01, 2004 2:36 pm
by feyd
.= is a concatenation operator.. it always makes strings.

you want += 1 I think...

Posted: Tue Jun 01, 2004 2:54 pm
by pickle
or just $num_right++

(is the if/elseif construct really necessary? You're doing the same thing in both clauses)

Posted: Tue Jun 01, 2004 3:43 pm
by cgroup
Thanks! I have no idea what I was thinking. :?

This is for a lottery type game where you pick four numbers between 1 and 9 so I used the if/else to check each number to see if it's right and if so add one to the total number right, but it probably would be better to use switch. Not sure.