Search code examples
phpforeachget

Storing only certain $_GET request values


Currently I have this code that stores all $_GET requests:

  $array_name = array();
  foreach ($_GET as $key => $value) {
      $array_name[] = "'%".escape_string($value)."%'";
  }

My goal is to somehow only store certain values, if for example I have 5 different $_GET request, named 1,2,3,4 and 5. I only want to store 1-3 in this array. How would this be possible?


Solution

  • $array_name = array();
    foreach ($_GET as $key => $value) {
      if(in_array($key, array(1, 2, 3)))
        $array_name[] = "'%".escape_string($value)."%'";
      }
    }
    

    It this what you are looking for?