Q:

PHP 5.3.0 USE identifier

I asked a question yesterday about the USE identifier and it was answered PHP 5.3.0 USE keyword -- how to backport in 5.2?.
However I've had to extend my script to do this twice and unsure how I accommodate both 
$available_event_objects  = array_filter($event_objects, function ($event_object) use ($week_events) { 
    // keep if the event is not in $week_events
    return !in_array($event_object, $week_events);
  });`

and 
$calendar_weeks[$week_count][$calendar_date] = array_filter($available_event_objects, function ($event_object) use ($date_pointer) { 
    // keep if the event is happening on this day
    return ($date_pointer >= $event_object->start_date && $date_pointer <= $event_object->end_date);
  });`

How can I change this to get it to work in 5.2.9?
Can someone point me in the right direction??
Cheers

A:

PHP did not have anonymous functions before 5.3. You must use any of the callback types instead. Because this gets more difficult and is not very idiomatic with use cases such as yours, I would advise you to apply an imperative programming style instead.
$available_event_objects = array();
foreach ($event_objects as $event_object) {
    if (in_array($event_object, $week_events)) {
        $available_event_objects[] = $event_object;
    }
}

That said, for this case you can freely use array_intersect, ie. $available_event_objects = array_intersect($week_events, $event_objects);

