3v4l.org

run code in 300+ PHP versions simultaneously
<?php $types = [ ['unique_codename' => 'cars', 'category' => 'vehicle', 'foo' => 'bar'], ['unique_codename' => 'fruit', 'category' => 'food', 'foo' => 'bar'], ['unique_codename' => 'vegetables', 'category' => 'food', 'foo' => 'bar'], ['unique_codename' => 'animals', 'category' => 'vehicle and food', 'foo' => 'bar'], ]; $products = [ ['codename' => 'fruit', 'name' => 'banana', 'other' => 'stuff'], ['codename' => 'fruit', 'name' => 'apple', 'other' => 'stuff'], ['codename' => 'vegetables', 'name' => 'cauliflower', 'other' => 'stuff'], ['codename' => 'cars', 'name' => 'audi', 'other' => 'stuff'], ['codename' => 'cars', 'name' => 'volvo', 'other' => 'stuff'], ]; foreach ($types as ['unique_codename' => $ucn, 'sorts' => &$ref[$ucn]]) { $ref[$ucn] = []; }; foreach ($products as ['codename' => $cn, 'name' => $ref[$cn][]['name']]); var_export($types);
Output for 8.1.32, 8.2.0 - 8.2.29, 8.3.0 - 8.3.28, 8.4.1 - 8.4.14, 8.5.0
array ( 0 => array ( 'unique_codename' => 'cars', 'category' => 'vehicle', 'foo' => 'bar', 'sorts' => array ( 0 => array ( 'name' => 'audi', ), 1 => array ( 'name' => 'volvo', ), ), ), 1 => array ( 'unique_codename' => 'fruit', 'category' => 'food', 'foo' => 'bar', 'sorts' => array ( 0 => array ( 'name' => 'banana', ), 1 => array ( 'name' => 'apple', ), ), ), 2 => array ( 'unique_codename' => 'vegetables', 'category' => 'food', 'foo' => 'bar', 'sorts' => array ( 0 => array ( 'name' => 'cauliflower', ), ), ), 3 => array ( 'unique_codename' => 'animals', 'category' => 'vehicle and food', 'foo' => 'bar', 'sorts' => array ( ), ), )
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:
88.18 ms | 408 KiB | 5 Q