3v4l.org

run code in 300+ PHP versions simultaneously
<?php $tests = array("HIV", "Chlamydia", "Gonorrhoea"); $years = [ '2011' => false, '2012' => false, '2013' => false, '2014' => false, '2015' => false, '2016' => false, '2017' => false ]; $this_year = date('Y'); if (!array_key_exists($this_year, $years)) { // add to the array: $years[$this_year] = false; } $tests_by_year = []; $test_obj = []; $obj_count = count($years); $obj_added = 0; foreach ( $tests as $value ) { foreach ($years as $year => $yval) { $tests_by_year[$value][$year] = 0; if ($obj_added <= $obj_count) { $test_obj[] = new \stdClass; } $obj_added++; } } var_dump($test_obj); $test_obj2 = [ 0 => new \stdClass, 1 => new \stdClass, 2 => new \stdClass, 3 => new \stdClass, 4 => new \stdClass, 5 => new \stdClass, 6 => new \stdClass, 7 => new \stdClass, 8 => new \stdClass, 9 => new \stdClass ]; $test_obj2[0]->y = (int)2011; $test_obj2[1]->y = (int)2012; $test_obj2[2]->y = (int)2013; $test_obj2[3]->y = (int)2014; $test_obj2[4]->y = (int)2015; $test_obj2[5]->y = (int)2016; $test_obj2[6]->y = (int)2017; $test_obj2[7]->y = (int)2018; $test_obj2[8]->y = (int)2019; $test_obj2[9]->y = (int)2020; var_dump($test_obj2); /* foreach ($tests_by_year as $key => $value) { $test_obj[0]->$key = $value['2011']; $test_obj[1]->$key = $value['2012']; $test_obj[2]->$key = $value['2013']; $test_obj[3]->$key = $value['2014']; $test_obj[4]->$key = $value['2015']; $test_obj[5]->$key = $value['2016']; $test_obj[6]->$key = $value['2017']; $test_obj[7]->$key = $value['2018']; $test_obj[8]->$key = $value['2019']; $test_obj[9]->$key = $value['2020']; }*/
Output for git.master, git.master_jit, rfc.property-hooks
array(9) { [0]=> object(stdClass)#1 (0) { } [1]=> object(stdClass)#2 (0) { } [2]=> object(stdClass)#3 (0) { } [3]=> object(stdClass)#4 (0) { } [4]=> object(stdClass)#5 (0) { } [5]=> object(stdClass)#6 (0) { } [6]=> object(stdClass)#7 (0) { } [7]=> object(stdClass)#8 (0) { } [8]=> object(stdClass)#9 (0) { } } array(10) { [0]=> object(stdClass)#10 (1) { ["y"]=> int(2011) } [1]=> object(stdClass)#11 (1) { ["y"]=> int(2012) } [2]=> object(stdClass)#12 (1) { ["y"]=> int(2013) } [3]=> object(stdClass)#13 (1) { ["y"]=> int(2014) } [4]=> object(stdClass)#14 (1) { ["y"]=> int(2015) } [5]=> object(stdClass)#15 (1) { ["y"]=> int(2016) } [6]=> object(stdClass)#16 (1) { ["y"]=> int(2017) } [7]=> object(stdClass)#17 (1) { ["y"]=> int(2018) } [8]=> object(stdClass)#18 (1) { ["y"]=> int(2019) } [9]=> object(stdClass)#19 (1) { ["y"]=> int(2020) } }

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
67.82 ms | 403 KiB | 8 Q