samedi 15 juillet 2017

PHP: if else statement in function with wildcard (if == anything)

I'm trying to build a function with an array as parameters and if else statement:

function myfunction($params){
  global $myArray;

  if ( !isset($params[0]) ){ $params[0] = ???????? } // I need a wildcard here
  if ( !isset($params[1]) ){ $params[1] = ???????? } // I need a wildcard here
  ....etc......

  foreach($myArray as $item){
     if ($item[0] == $params[0]){
         if ($item[1] == $params[1]){
             $count += $item
         }
     }

  return $count;
}

Now I have several $params[keys] to check this way.

I need to assign a default value to params[key], so that, if it is not given, the function will take all the $item. Thanks

Aucun commentaire:

Enregistrer un commentaire