Skip to content

Instantly share code, notes, and snippets.

@ratacibernetica
Created July 5, 2019 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ratacibernetica/d3c3f102f22fb6b4414d94bfbd167d6c to your computer and use it in GitHub Desktop.
Save ratacibernetica/d3c3f102f22fb6b4414d94bfbd167d6c to your computer and use it in GitHub Desktop.
php filter array
<?php
/**
* Removes unwanted key|values from array.
* @param array $filters
* @return array
*/
function applyFilters(array $request){
$allowedFields = ['field_1','field_2','field_3','field_4'];
$filters = array_intersect_key($request, array_flip($allowedFields));
return $filters;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment