mardi 16 juin 2020

Alternative to large amout of if /else if statements PHP [closed]

If there is a large amount of if statements, say that I have to compare each element of a big array with a lot of case (eg 100 test cases), is there a more efficient way to search through the case

$x[0] //user input

if($x[0] == 1)
     dosomething();
elseif ($x[0] ==2)
    thing1();
....
elseif($x[0] == 100)
    thing100();

Aucun commentaire:

Enregistrer un commentaire