3v4l.org

run code in 300+ PHP versions simultaneously
<?php $rows = [ ['id' => 1, 'name' => 'foo', 'year' => 2017, 'month' => 1, 'value' => 'bar1'], ['id' => 2, 'name' => 'foo', 'year' => 2017, 'month' => 2, 'value' => 'bar2'], ['id' => 3, 'name' => 'foo', 'year' => 2017, 'month' => 3, 'value' => 'bar3'], ['id' => 4, 'name' => 'foo', 'year' => 2017, 'month' => 4, 'value' => 'bar4'], ]; $data = []; foreach($rows as $row) { $key = $row['name'] . '_' . $row['year']; if(!isset($data[$key])){ $data[$key] = array( 'id' => $row['id'], 'name' => $row['name'], 'year' => $row['year'], ); } $month = 'month' . $row['month']; $data[$key][$month] = $row['value']; } print_r($data);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [foo_2017] => Array ( [id] => 1 [name] => foo [year] => 2017 [month1] => bar1 [month2] => bar2 [month3] => bar3 [month4] => bar4 ) )

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:
157.37 ms | 406 KiB | 5 Q