Created
October 17, 2016 11:30
-
-
Save romanitalian/dd3e4b323dfa137f3999a07d7b1bf085 to your computer and use it in GitHub Desktop.
Фильтруем массив по значениям
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
$rows = array('a' => 1, 'b' => 2); | |
$f = array(2 => true); | |
function array_filter_by_values($_rows, $_filter_keys) { | |
$filter = function($key) use ($_filter_keys) {return isset($_filter_keys[$key]) && $_filter_keys[$key];}; | |
$out = array_filter($_rows, $filter); | |
return $out; | |
} | |
$t = array_filter_by_values($rows, $f); | |
var_dump($t); | |
// array(1) { | |
// ["b"]=> | |
// int(2) | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment