Created — forked from ruprict/build_params.php

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

Retrieve whitelisted set of parameters

View with_5.4.php
1 2 3 4 5 6 7 8 9 10 11
<?php
function filter_params(array $params = [], array $whitelist = []) {
return array_map('trim', array_intersect_key($params, array_flip($whitelist)));
}
$params = ['is_admin' => 1, 'name' => ' Bob', 'surname' => 'Smith '];
$whitelist = ['name', 'surname'];
// these are your whitelisted parameters (please don't forget to filter/validate before persisting)
var_dump(filter_params($params, $whitelist));
View with_5.4.php
1 2 3 4 5 6 7 8 9 10 11
<?php
function filter_params(array $params = array(), array $whitelist = array()) {
return array_map('trim', array_intersect_key($params, array_flip($whitelist)));
}
$params = array('is_admin' => 1, 'name' => ' Bob', 'surname' => 'Smith ');
$whitelist = array('name', 'surname');
// these are your whitelisted parameters (please don't forget to filter/validate before persisting)
var_dump(filter_params($params, $whitelist));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.