3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['spubid' => 'A00502','sfirst'=>'J.','smi'=>'A.','slast'=>'Doe'], ['spubid' => 'A00502','sfirst'=>'J.','smi'=>'F.','slast'=>'Kennedy'], ['spubid' => 'A00502','sfirst'=>'B.','smi'=>'F.','slast'=>'James'], ['spubid' => 'BXXXXX','sfirst'=>'B.','smi'=>'F.','slast'=>'James'], ['spubid' => 'A00502','sfirst'=>'S.','smi'=>'M.','slast'=>'Williamson'], ]; $result = []; foreach ($array as $row) { $id = $row['spubid']; if (!isset($ref[$id])) { $ref[$id] = $row; $counter[$id] = 0; $result[] = &$ref[$id]; } else { unset($row['spubid']); ++$counter[$id]; foreach ($row as $k => $v) { $ref[$id][$k . $counter[$id]] = $v; } } } var_export($result);
Output for 8.1.0 - 8.1.34, 8.2.0 - 8.2.30, 8.3.0 - 8.3.29, 8.4.1 - 8.4.14, 8.4.16 - 8.4.17, 8.5.0 - 8.5.2
array ( 0 => array ( 'spubid' => 'A00502', 'sfirst' => 'J.', 'smi' => 'A.', 'slast' => 'Doe', 'sfirst1' => 'J.', 'smi1' => 'F.', 'slast1' => 'Kennedy', 'sfirst2' => 'B.', 'smi2' => 'F.', 'slast2' => 'James', 'sfirst3' => 'S.', 'smi3' => 'M.', 'slast3' => 'Williamson', ), 1 => array ( 'spubid' => 'BXXXXX', 'sfirst' => 'B.', 'smi' => 'F.', 'slast' => 'James', ), )
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.

preferences:
103.21 ms | 407 KiB | 5 Q