3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'abc' => [ [ 'foo' => '*', 'action' => 'Read', 'resource' => [ 'name' => 'name_1', 'patternType' => 'fixed', 'type' => 'partition', ], ], [ 'foo' => '*', 'action' => 'Write', 'resource' => [ 'name' => 'name_1', 'patternType' => 'fixed', 'type' => 'partition', ], ], [ 'foo' => '*', 'action' => 'Read', 'resource' => [ 'name' => 'name_2', 'patternType' => 'fixed', 'type' => 'partition', ], ], [ 'foo' => '*', 'action' => 'Alter', 'resource' => [ 'name' => 'name_2', 'patternType' => 'fixed', 'type' => 'partition', ], ], ], ]; foreach ($array as $key => &$sets) { foreach ($sets as $i => &$set) { $id = $set['resource']['name']; if (!isset($ref[$id])) { $set['action'] = (array) $set['action']; $ref[$id] = &$set['action']; } else { $ref[$id][] = $set['action']; unset($array[$key][$i]); } } } var_export($array);
Output for 8.0.1 - 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
array ( 'abc' => array ( 0 => array ( 'foo' => '*', 'action' => array ( 0 => 'Read', 1 => 'Write', ), 'resource' => array ( 'name' => 'name_1', 'patternType' => 'fixed', 'type' => 'partition', ), ), 2 => array ( 'foo' => '*', 'action' => array ( 0 => 'Read', 1 => 'Alter', ), 'resource' => array ( 'name' => 'name_2', 'patternType' => 'fixed', 'type' => 'partition', ), ), ), )
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:
114.58 ms | 408 KiB | 5 Q