3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $itineraries_params = 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 elnfp
Output for 5.4.2 - 7.2.0
array(5) { [0]=> array(2) { [0]=> object(stdClass)#2 (4) { ["weekday"]=> int(1) ["arrival_time"]=> string(8) "09:00:00" ["from_address_id"]=> int(1) ["to_address_id"]=> int(2) } [1]=> object(stdClass)#3 (4) { ["weekday"]=> int(1) ["arrival_time"]=> string(8) "17:00:00" ["from_address_id"]=> int(2) ["to_address_id"]=> int(1) } } [1]=> array(2) { [0]=> object(stdClass)#4 (4) { ["weekday"]=> int(2) ["arrival_time"]=> string(8) "09:00:00" ["from_address_id"]=> int(1) ["to_address_id"]=> int(2) } [1]=> object(stdClass)#5 (4) { ["weekday"]=> int(2) ["arrival_time"]=> string(8) "17:00:00" ["from_address_id"]=> int(2) ["to_address_id"]=> int(1) } } [2]=> array(2) { [0]=> object(stdClass)#6 (4) { ["weekday"]=> int(3) ["arrival_time"]=> string(8) "09:00:00" ["from_address_id"]=> int(1) ["to_address_id"]=> int(2) } [1]=> object(stdClass)#7 (4) { ["weekday"]=> int(3) ["arrival_time"]=> string(8) "17:00:00" ["from_address_id"]=> int(2) ["to_address_id"]=> int(1) } } [3]=> array(2) { [0]=> object(stdClass)#8 (4) { ["weekday"]=> int(4) ["arrival_time"]=> string(8) "09:00:00" ["from_address_id"]=> int(1) ["to_address_id"]=> int(2) } [1]=> object(stdClass)#9 (4) { ["weekday"]=> int(4) ["arrival_time"]=> string(8) "17:00:00" ["from_address_id"]=> int(2) ["to_address_id"]=> int(1) } } [4]=> array(2) { [0]=> object(stdClass)#10 (4) { ["weekday"]=> int(5) ["arrival_time"]=> string(8) "09:00:00" ["from_address_id"]=> int(1) ["to_address_id"]=> int(2) } [1]=> object(stdClass)#11 (4) { ["weekday"]=> int(5) ["arrival_time"]=> string(8) "17:00:00" ["from_address_id"]=> int(2) ["to_address_id"]=> int(1) } } }
Output for 5.3.18 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/dg6kr on line 5
Process exited with code 255.