Skip to content

Instantly share code, notes, and snippets.

@gianlucacandiotti
Last active December 20, 2015 00:03
Show Gist options
  • Save gianlucacandiotti/bf6292fad850fe87c3aa to your computer and use it in GitHub Desktop.
Save gianlucacandiotti/bf6292fad850fe87c3aa to your computer and use it in GitHub Desktop.
// Params to filter
$params = [
'param_1',
'param_2',
'param_3'
];
// an array of objects
$objects_array = [];
$data = [];
foreach ( $objects_array as $object ){
$object_data = (array)$object;
$data[] = array_filter($object_data, function($object_data_key) use($params){
return in_array($object_data_key, $params);
}, ARRAY_FILTER_USE_KEY);
}
return $data;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment