Page 1 of 1
Streamlining Code
Posted: Tue Jan 07, 2003 5:45 am
by Deddog
if ($row["SpeedDial"] === 'Spd' or $row["SpeedDial"] === 'spd' or $row["SpeedDial"] == 'n/a' or $row["SpeedDial"]==='') :
How can i change the above code to be more efficient?
Can't find commands like "in".
If $row["SpeedDial"] in ('spd','Spd', ect ect
Cheers,
Lee.
Posted: Tue Jan 07, 2003 5:58 am
by Elmseeker
Code: Select all
if ($row["SpeedDial"] === ('Spd' || 'spd' || 'n/a' || ''));
That should turn the trick...not positive though, never tried it in PHP, works in C/C++ though.

Posted: Tue Jan 07, 2003 6:05 am
by DaZZleD
you could just define an array with all the possible values $row["SpeedDial"] can have. then use a for to make the comparisons:
Code: Select all
$possible_values = array("Spd", "spd", "n/a"...);
$found = 0;
for($x=0; $x<count($possible_values); $x++)
{
if($rowї"SpeedDial"] === $possible_valuesї$x])
{
$found = $possible_valuesї$x];
}
}
if($found == 0)
{
//$rowї"SpeedDial"] didn't have any of the values in $possible_values
}
else
{
//$rowї"SpeedDial"] had one of the values in $possible_values ($found)
}
Posted: Tue Jan 07, 2003 6:18 am
by EvilWalrus
Elmseekers function would only work if the values were integers, not strings, and the 'in' command is only native to Perl. Use the suggested array solution to make it a little nicer.
Posted: Tue Jan 07, 2003 6:21 am
by Elmseeker
That is very good to know, thanks for the info Oh Evil One!
And Dazzled,
i did all this single-handed
Very sorry to hear about your loss, ever thought of getting a prosthetic hand?

Posted: Tue Jan 07, 2003 6:31 am
by DaZZleD
very funny!
