3v4l.org

run code in 300+ PHP versions simultaneously
<?php $result= []; $names = ['TestAgent', 'TestAgent1', 'TestAgent1', 'TestAgent2', 'TestAgent2', 'TestAgent2']; $values = ['2019-04', '2019-05', '2019-06', '2019-04', '2019-05', '2019-06']; $counts = array_count_values($names); $offset = 0; foreach (array_values(array_unique($names)) as $key=>$name) { $slice = array_slice($values, $offset, $counts[$name]); $offset += count($slice); $result[$name] = $slice; } print_r($result);
Output for 7.1.25 - 7.1.30, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 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 - 8.5.1
Array ( [TestAgent] => Array ( [0] => 2019-04 ) [TestAgent1] => Array ( [0] => 2019-05 [1] => 2019-06 ) [TestAgent2] => Array ( [0] => 2019-04 [1] => 2019-05 [2] => 2019-06 ) )
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:
193.27 ms | 407 KiB | 5 Q