Skip to content

Commit

Permalink
Added a helper to filter an array white a white list
Browse files Browse the repository at this point in the history
  • Loading branch information
emiliodeg authored and niden committed Jun 14, 2019
1 parent b843304 commit df6fa15
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions phalcon/Helper/Arr.zep
Original file line number Diff line number Diff line change
Expand Up @@ -395,4 +395,44 @@ class Arr

return array_filter(collection, method);
}

/**
* White list filter by key: obtain elements of an array filtering
* by the keys obtained from the elements of a whitelist
*
* @param array $collection
* @param array $whiteList
*
* @return array
*/
final public static function whiteList(array! collection, array! whiteList) -> array
{
array result;


let whiteList = array_filter(
whiteList,
function (element)
{
if (is_int(element)) {
return true;
}

if (is_string(element)) {
let element = trim(element);

return mb_strlen(element) > 0;
}

return false;
}
);

let result = array_intersect_key(
collection,
array_flip(whiteList)
);

return result;
}
}

0 comments on commit df6fa15

Please sign in to comment.