<?php $arr = ['black', 'white and black', 'lion', 'fast', 'zebra', 'lion is fast', 'zebra is white']; $str = "zebra is white and black, and lion is fast"; function sortl($a,$b){ return strlen($b)-strlen($a); } usort($arr,'sortl'); foreach($arr as $s){ if(strpos($str, $s) !== false){ $new[] = $s; $str = str_replace($s, "", $str); } } Var_dump($new);
You have javascript disabled. You will not be able to edit any code.