3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ 'relation' => 'AND', [ 'taxonomy' => 'merk', 'field' => 'slug', 'terms' => ['coral'] ], [ 'taxonomy' => 'foo', 'field' => 'bar', 'terms' => ['stackoverflow'] ], [ 'taxonomy' => 'merk', 'field' => 'slug', 'terms' => ['deluxe', 'ultra'] ] ]; foreach ($array as $key => &$item) { if (is_array($item) && isset($item['taxonomy'], $item['field'])) { $id = $item['taxonomy'] . '_' . $item['field']; if (!isset($ref[$id])) { $ref[$id] = &$item['terms']; } else { array_push($ref[$id], ...$item['terms']); unset($array[$key]); } } } var_export($array);
Output for git.master, git.master_jit, rfc.property-hooks
array ( 'relation' => 'AND', 0 => array ( 'taxonomy' => 'merk', 'field' => 'slug', 'terms' => array ( 0 => 'coral', 1 => 'deluxe', 2 => 'ultra', ), ), 1 => array ( 'taxonomy' => 'foo', 'field' => 'bar', 'terms' => array ( 0 => 'stackoverflow', ), ), )

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:
91.08 ms | 406 KiB | 5 Q