3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['brand' => 'ABC', 'model' => 'xyz', 'size' => 13], ['brand' => 'QWE', 'model' => 'poi', 'size' => 23], ['brand' => 'ABC', 'model' => 'xyz', 'size' => 18] ]; $result = []; foreach ($array as $row) { $compositeKey = $row['brand'] . '_' . $row['model']; if (!isset($result[$compositeKey])) { $result[$compositeKey] = $row; } else { $result[$compositeKey]['size'] = array_merge((array)$result[$compositeKey]['size'], [$row['size']]); } } var_export(array_values($result));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'brand' => 'ABC', 'model' => 'xyz', 'size' => array ( 0 => 13, 1 => 18, ), ), 1 => array ( 'brand' => 'QWE', 'model' => 'poi', 'size' => 23, ), )

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