3v4l.org

run code in 300+ PHP versions simultaneously
<?php $myString = "type:blue, type:red, shift:second, shift:first, category:circle, system:unknown"; $params = explode( ", ", $myString ); $possibleKeys = [ "category", "shift", "type", "chances" ]; $ignore = ['system']; $nodes = []; foreach ($params as $param) { $node = explode( ":", $param ); if (in_array( $node[0], $possibleKeys )) { $nodes[$node[0]][] = $node[1]; } else { $nodes[$node[0]] = $node[1]; } } foreach($ignore as $key) { unset($nodes[$key]); } print '<pre>'; print_r($nodes); print '</pre>'; ?>
Output for 7.1.0 - 7.1.21, 7.2.0 - 7.2.33, 7.3.16 - 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.28, 8.4.1 - 8.4.14, 8.5.0 - 8.5.1
<pre>Array ( [type] => Array ( [0] => blue [1] => red ) [shift] => Array ( [0] => second [1] => first ) [category] => Array ( [0] => circle ) ) </pre>
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:
187.42 ms | 407 KiB | 5 Q