3v4l.org

run code in 300+ PHP versions simultaneously
<?php $fruits = array("apple","orange","papaya","grape","apple juice", "applecurd"); $content = "eaplp"; $content = str_split($content); $count = count($content); Foreach($fruits as $fruit){ $arr_fruit = str_split($fruit); $SortCont = array_merge(array_intersect($arr_fruit, $content), array_diff($content, $arr_fruit)); If(array_slice($SortCont, 0, $count) == array_slice($arr_fruit, 0, $count)){ Echo "match: " . $fruit ."\n"; } }
based on Qpebo
Output for 7.1.0 - 7.1.20, 7.2.0 - 7.2.31, 7.3.16 - 7.3.19, 7.4.0 - 7.4.7, 8.0.0alpha1 - alpha2
match: apple match: apple juice match: applecurd