fork download
  1. <?php
  2.  
  3. $arr1 = ['ly', 'ful', 'ay'];
  4. $arr2 = ['beautiful', 'lovely', 'power'];
  5.  
  6. $result = array_filter($arr2, function($word) use ($arr1){
  7. $word_length = strlen($word);
  8. return array_reduce($arr1, function($result, $suffix) use ($word, $word_length) {
  9. if($word_length > strlen($suffix))
  10. $result = $result || 0 === substr_compare($word, $suffix, -strlen($suffix), $word_length);
  11. return $result;
  12. }, false);
  13. });
  14.  
  15. print_r($result);
Success #stdin #stdout 0.01s 20520KB
stdin
Standard input is empty
stdout
Array
(
    [0] => beautiful
    [1] => lovely
)