3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function mysort($a,$b){ return strlen($b)-strlen($a); } //$data = array("kaushik","kaushik is","kaushik is great","is","is great","great"); $data = array("usb","pc","cam 168","cam","168"); usort($data,'mysort'); // print_r($data); $current = ""; for($i=0;$i<count($data);$i++) { $current=$data[$i]; for($j=0;$j<count($data);$j++) { if($i<>$j) { if((str_replace($data[$j],"",$current))!=$current) { $data[$j]=""; }; } } } print_r($data); ?>
Output for hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
Array ( [0] => cam 168 [1] => usb [2] => [3] => [4] => pc )
Output for 4.3.0 - 5.6.28
Array ( [0] => cam 168 [1] => [2] => [3] => usb [4] => pc )