3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cats = [ ['id' => 1, 'category_style_code' => 'GA'], ['id' => 2, 'category_style_code' => 'PA'], ['id' => 3, 'category_style_code' => 'CA'], ['id' => 4, 'category_style_code' => 'MA'] ]; $prods = [ ['id' => 1, 'default_price' => 37.50, 'category_code' => 'MA'], ['id' => 2, 'default_price' => 36.50, 'category_code' => 'GA'], ['id' => 3, 'default_price' => 38.50, 'category_code' => 'CA'], ['id' => 4, 'default_price' => 39.50, 'category_code' => 'GA'], ]; $associative_cats = array_column($cats, null, 'category_style_code'); foreach ($prods as $row) { if (isset($associative_cats[$row['category_code']])) { $associative_cats[$row['category_code']]['products'][] = $row; } } var_export(array_values($associative_cats));
Output for git.master, git.master_jit, rfc.property-hooks
array ( 0 => array ( 'id' => 1, 'category_style_code' => 'GA', 'products' => array ( 0 => array ( 'id' => 2, 'default_price' => 36.5, 'category_code' => 'GA', ), 1 => array ( 'id' => 4, 'default_price' => 39.5, 'category_code' => 'GA', ), ), ), 1 => array ( 'id' => 2, 'category_style_code' => 'PA', ), 2 => array ( 'id' => 3, 'category_style_code' => 'CA', 'products' => array ( 0 => array ( 'id' => 3, 'default_price' => 38.5, 'category_code' => 'CA', ), ), ), 3 => array ( 'id' => 4, 'category_style_code' => 'MA', 'products' => array ( 0 => array ( 'id' => 1, 'default_price' => 37.5, 'category_code' => 'MA', ), ), ), )

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:
52.78 ms | 403 KiB | 8 Q