3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr1 = ['word', 'chord', 'tech', 'care', 'kek', 'lol', 'wild', 'regex']; $arr2 = ['ord', 'ek', 'ol', 'ld', 'gex', 'ss']; $keys=[]; foreach($arr2 as $val){ $matches = preg_grep("/.+" . preg_quote($val) . "/", $arr1); $keys = array_merge($keys, array_keys($matches)); // save keys of matched words foreach($matches as $key => $m) $new[$val][] = str_replace($val, "_$val", $arr1[$key]); } $new['unmatched'] = array_diff_key($arr1, array_flip($keys)); // add unmatched words var_dump($new);
Output for git.master_jit, git.master, rfc.property-hooks
array(6) { ["ord"]=> array(2) { [0]=> string(5) "w_ord" [1]=> string(6) "ch_ord" } ["ek"]=> array(1) { [0]=> string(4) "k_ek" } ["ol"]=> array(1) { [0]=> string(4) "l_ol" } ["ld"]=> array(1) { [0]=> string(5) "wi_ld" } ["gex"]=> array(1) { [0]=> string(6) "re_gex" } ["unmatched"]=> array(2) { [2]=> string(4) "tech" [3]=> string(4) "care" } }

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:
65.9 ms | 402 KiB | 8 Q