DEV Community

Discussion on: Can you simplify this code for the guy?

Collapse
 
starboysharma profile image
Pankaj Sharma

I have two solutions:

  1. In this case, you should use switch case because they are faster in comparison of if-else statement and more cleaner syntax.

  2. But what if you don't want to write every time if else if try this

<?php
$compare_length = 20;
$match = 7;
for ($i = 1; $i < $compare_length) {
if ($match === $i) {
echo 'Match Found';
break;
}
}

?>