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 git.master_jit, git.master
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 ( ), ), )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
54.14 ms | 408 KiB | 5 Q