Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting a PHP anonymous function to non-anonymous
    primarykey
    data
    text
    <p>I asked a related question before I lost my login id - <a href="https://stackoverflow.com/questions/3723748/php-version-5-2-14-parse-error-syntax-error-unexpected-t-function-expecting">PHP Version 5.2.14 / Parse error: syntax error, unexpected T_FUNCTION, expecting &#39;)&#39;</a> - but this is the "entire" problem.</p> <p>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!</p> <p>The entire function is pasted below, but only the areas pointed out are the ones that PHP 5.2.14 complains about..</p> <pre><code>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-&gt;setTimezone($tz2); } return $res; }, $convertedAvail ); // ISSUE_END $res = array(); foreach ($times as $t) { $t1 = reset($t); $t2 = next($t); if ($t1-&gt;format("d") == $t2-&gt;format("d")) { $res[$t1-&gt;format("l")][] = $t1-&gt;format("g:i a") . " to ". $t2-&gt;format("g:i a"); } else { $res[$t1-&gt;format("l")][] = $t1-&gt;format("g:i a") . " to 11:59 pm"; $res[$t2-&gt;format("l")][] = "12:00 am to ". $t2-&gt;format("g:i a"); } } return $res; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload