I have this array:
$arr_to_filter = array(1, 3, 5, 7, 10, 12, 15);
$filter = array(0, 1, 1, 0, 1);
Expected result:
Array (
[0] => 3
[1] => 5
[2] => 10
)
I can achieve this by this loop:
$arr_to_filter = array(1, 3, 5, 7, 10, 12, 15);
$filter = array(0, 1, 1, 0, 1);
$output_array = array();
foreach($arr_to_filter as $key=>$val) {
if(isset($filter[$key]) && $filter[$key]) {
$output_array[] = $val;
}
}
print_r($output_array);
Can i achieve this using built in functions like array_filter or another built in function without using loops?