Hi,
I asked a related question before I lost my login id - http://stackoverflow.com/questions/3723748/php-version-5-2-14-parse-error-syntax-error-unexpected-t-function-expecting - but this is the "entire" problem.
I'm having a hard time figuring out how to convert this function (got from somewhere on SO) to work with PHP 5.2.14 (which as folks informed me - does not support anonymous functions). I tried a few permutations of changing the code to make it work with array_map() but I cant wrap my head around how everything works!
The entire function is pasted below, but only the areas pointed out are the ones that PHP 5.2.14 complains about..
function convertGeneralAvailabilityTime($date,$from_timezone,$from_timebegin, $from_timeend, $to_timezone)
{
$tz1 = new DateTimezone($from_timezone);
$datetime1 = new DateTime("$date $from_timebegin", $tz1);
$datetime2 = new DateTime("$date $from_timeend", $tz1);
$convertedAvail = array(
array($datetime1, $datetime2),
);
$tz2 = new DateTimezone($to_timezone);
//convert periods:
// ISSUE_START
$times = array_map(
function (array $p) use ($tz2) {
$res = array();
foreach ($p as $d) {
$res[] = $d->setTimezone($tz2);
}
return $res;
},
$convertedAvail
);
// ISSUE_END
$res = array();
foreach ($times as $t) {
$t1 = reset($t);
$t2 = next($t);
if ($t1->format("d") == $t2->format("d")) {
$res[$t1->format("l")][] = $t1->format("g:i a") . " to ".
$t2->format("g:i a");
}
else {
$res[$t1->format("l")][] = $t1->format("g:i a") . " to 11:59 pm";
$res[$t2->format("l")][] = "12:00 am to ". $t2->format("g:i a");
}
}
return $res;
}