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 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27, 8.4.1 - 8.4.14, 8.5.0
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', ), )
Output for 8.4.15
/bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.4.15) /bin/php-8.4.15: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.4.15)
Process exited with code 1.
Output for 8.3.28
/bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libm.so.6: version `GLIBC_2.35' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.34' not found (required by /bin/php-8.3.28) /bin/php-8.3.28: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /bin/php-8.3.28)
Process exited with code 1.

preferences:
88.89 ms | 407 KiB | 5 Q