3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ [ 'key_1' => 'FOO', 'key_2' => 'FTU-1', 'cats' => '/30/' ], [ 'key_1' => 'FOO', 'key_2' => 'FTU-2', 'cats' => '/30/' ], [ 'key_1' => 'FOO', 'key_2' => 'FTU-3', 'cats' => '/30/10/' ], [ 'key_1' => 'FOO', 'key_2' => 'FTU-4', 'cats' => '/15/' ], [ 'key_1' => 'FOO', 'key_2' => 'FTU-5', 'cats' => '/10/' ], [ 'key_1' => 'FOO', 'key_2' => 'FTU-6', 'cats' => '/15/' ], ]; $result = []; foreach ($array as $row) { $cats = preg_split('#/#', $row['cats'], 0, PREG_SPLIT_NO_EMPTY); foreach ($cats as $cat) { $result[$cat][] = $row; } } var_export($result);
Output for 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
array ( 30 => array ( 0 => array ( 'key_1' => 'FOO', 'key_2' => 'FTU-1', 'cats' => '/30/', ), 1 => array ( 'key_1' => 'FOO', 'key_2' => 'FTU-2', 'cats' => '/30/', ), 2 => array ( 'key_1' => 'FOO', 'key_2' => 'FTU-3', 'cats' => '/30/10/', ), ), 10 => array ( 0 => array ( 'key_1' => 'FOO', 'key_2' => 'FTU-3', 'cats' => '/30/10/', ), 1 => array ( 'key_1' => 'FOO', 'key_2' => 'FTU-5', 'cats' => '/10/', ), ), 15 => array ( 0 => array ( 'key_1' => 'FOO', 'key_2' => 'FTU-4', 'cats' => '/15/', ), 1 => array ( 'key_1' => 'FOO', 'key_2' => 'FTU-6', 'cats' => '/15/', ), ), )
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:
81.45 ms | 408 KiB | 5 Q