Posted by Henk Oegema on 04/21/07 21:46
Vince Morgan wrote:
>
> for($i=0; $i<strlen($string); $i++)
> {
> if($string[$i] < "5")
> {
> $string[$i] = $string[$i] + 5;
> }else
> {
> $string[$i] = $string[$i] - 5;
> }
> }
>
The above for-loop doesn't give the same result as the else-if loop.(in my
original thread)
This one (from Jeff) does:
for ($i=0;$i<strlen($string);$i++)
{
$chr = $string{$i};
switch($chr)
{
case "0" : $string[$i] = "5"; break;
case "1" : $string[$i] = "6"; break;
case "2" : $string[$i] = "7"; break;
case "3" : $string[$i] = "8"; break;
case "4" : $string[$i] = "9"; break;
case "5" : $string[$i] = "0"; break;
case "6" : $string[$i] = "1"; break;
case "7" : $string[$i] = "2"; break;
case "8" : $string[$i] = "3"; break;
case "9" : $string[$i] = "4"; break;
}
}
Grds.
Henk
[Back to original message]
|