Tuesday, 6 August 2013

php - using strpos() to replace multiple comparisons in an if statement

php - using strpos() to replace multiple comparisons in an if statement

Is it OK to replace multiple comparisons by using strpos()?
Example:
changing
if ( $linecounter == $extra1 || $linecounter == $ extra2 || $linecounter
== 5 )
{
...
}
to
$ok = ' ' . $extra1 . $extra2 . '5';
if ( strpos($ok, $linecounter) > 0 )
{
...
}

No comments:

Post a Comment