mardi 10 novembre 2015

PHP: Loop variables for if-statement

Hi I've got three actual variables and one that keeps the number of existing variables.

$car1
$car2
$car3
$numberOfVariables = count($anUnimportantArray);

With these variables I need to do an if loop, like this

if($anothervariable == $car1 | $anothervariable == $car2 | $anothevariable == $car3)
{
      // something happens 
}

Now I want a function that can create this "if loop" dynamically with the help of the "$numberOfVariables" which holds the information how many variables exist. All my existing variable are named "car" + a number.

So if I would have more than three "$car" variables the function would create the loop with every existing car variable.

Aucun commentaire:

Enregistrer un commentaire