@pathros:
To use a different value for filtering, the solution is as follows: (TESTED :-))
$my_array = array(
0 => array(
'cat' => '1',
'value' => 'Value A'
)
,
1 => array(
'cat' => '2',
'value' => 'Value B'
)
,
2 => array(
'cat' => '0',
'value' => 'Value C'
)
,
3 => array(
'cat' => '1',
'value' => 'Value D'
)
);
function my_filtering_function($in_array) {
return is_array($in_array) && $in_array['cat'] == $GLOBALS['filter_param_1'];
}
$GLOBALS['filter_param_1'] = 2;
$filtered_array = array_filter($my_array, 'my_filtering_function');
e('Number of matching records : '.count($filtered_array)).'record(s)<br>';
$GLOBALS['filter_param_1'] = 1;
$filtered_array = array_filter($my_array, 'my_filtering_function');
e('Number of matching records : '.count($filtered_array)).'record(s)<br>';
source
share