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.
Streamlining Code
Moderator: General Moderators
Code: Select all
if ($row["SpeedDial"] === ('Spd' || 'spd' || 'n/a' || ''));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)
}- EvilWalrus
- Site Admin
- Posts: 209
- Joined: Thu Apr 18, 2002 3:21 pm
- Location: Springmont, PA USA