3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'company' => 'One', 'price' => 10 ], [ 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'company' => 'Two', 'price' => 15 ], [ 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'company' => 'Three', 'price' => 20 ], [ 'id' => 224, 'name' => 'Paul', 'country' => 'France', 'age' => 25, 'company' => 'One', 'price' => 25 ], [ 'id' => 224, 'name' => 'Paul', 'country' => 'France', 'age' => 25, 'company' => 'Two', 'price' => 40 ] ]; $result = []; foreach ($array as $row) { $companies = array_splice($row, -2); $result[$row['id']] ??= $row; $result[$row['id']]['companies'][] = $companies; } var_export($result);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 112 => array ( 'id' => 112, 'name' => 'John', 'country' => 'Spain', 'age' => 24, 'companies' => array ( 0 => array ( 'company' => 'One', 'price' => 10, ), 1 => array ( 'company' => 'Two', 'price' => 15, ), 2 => array ( 'company' => 'Three', 'price' => 20, ), ), ), 224 => array ( 'id' => 224, 'name' => 'Paul', 'country' => 'France', 'age' => 25, 'companies' => array ( 0 => array ( 'company' => 'One', 'price' => 25, ), 1 => array ( 'company' => 'Two', 'price' => 40, ), ), ), )

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:
80.72 ms | 407 KiB | 5 Q