3v4l.org

run code in 300+ PHP versions simultaneously
<?php $colors = array ('red','blue','green','yellow'); $boxes = array ('circular','squared','hexagonal','triangular'); $possible_combos = array ( array('circular','red','blue'), array('squared','red','green'), array('hexagonal','blue','yellow'), array('triangular','red','green') ); // collect constraints ordered by rarest foreach ($possible_combos as $constraint) { $box = array_shift($constraint); foreach ($constraint as $color) { $constraints[$color] []= $box; } } // assign rarest first to last asort($constraints); foreach ($constraints as $color => $allowedBoxes) { foreach ($allowedBoxes as $box) { $key = array_search($box, $boxes); // if we have a match, then remove it from the collection if ($key !== false) { $result[$box] = $color; unset($boxes[$key]); continue 2; } } } print_r($result);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [hexagonal] => yellow [circular] => blue [squared] => green [triangular] => red )

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:
115.29 ms | 405 KiB | 5 Q