3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $itineraries_params = array_reduce(array_map( function ($weekday) { return [ (object) [ 'weekday' => $weekday, 'arrival_time' => '09:00:00', 'from_address_id' => 1, 'to_address_id' => 2 ], (object) [ 'weekday' => $weekday, 'arrival_time' => '17:00:00', 'from_address_id' => 2, 'to_address_id' => 1 ] ]; }, range(1, 5) )); var_dump($itineraries_params); // vrs Ruby // // itineraries_params = (1..5).flat_map do |weekday| // [{ // weekday: weekday, // arrival_time: '09:00:00', // from_address_id: user.home_address.id, // to_address_id: user.work_address.id // }, { // weekday: weekday, // arrival_time: '17:00:00', // from_address_id: user.work_address.id, // to_address_id: user.home_address.id // }] // end
based on dg6kr
Output for 7.0.0 - 7.2.0
Warning: array_reduce() expects at least 2 parameters, 1 given in /in/5K9mh on line 20 NULL
Output for 5.4.1 - 5.6.28
Warning: array_reduce() expects at least 2 parameters, 1 given in /in/5K9mh on line 21 NULL
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/5K9mh on line 5
Process exited with code 255.