3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-17', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-18', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'square', 'startdate' => '2011-08-20', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-22', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-20', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-23', ], [ 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-19', ], ]; usort($array, fn($a, $b) => $a['startdate'] <=> $b['startdate']); $result = []; foreach ($array as $row) { $compositeKey = implode( '_', [$row['color'], $row['size'], $row['shape']] ); if ( !isset($ref[$compositeKey]) || ($row['startdate'] != date('Y-m-d', strtotime(($ref[$compositeKey]['enddate'] ?? $ref[$compositeKey]['startdate']) . ' + 1 day'))) ) { if (isset($ref[$compositeKey])) { unset($ref[$compositeKey]); } $ref[$compositeKey] = $row; $result[] =& $ref[$compositeKey]; } else { $ref[$compositeKey]['enddate'] = $row['startdate']; } } var_export($result);
Output for git.master, git.master_jit
array ( 0 => array ( 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-17', 'enddate' => '2011-08-20', ), 1 => array ( 'color' => 'red', 'size' => 'large', 'shape' => 'square', 'startdate' => '2011-08-20', ), 2 => array ( 'color' => 'red', 'size' => 'large', 'shape' => 'circle', 'startdate' => '2011-08-22', 'enddate' => '2011-08-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:
69.33 ms | 406 KiB | 5 Q