fork download
  1. <?php
  2. $getpositions = [
  3. 'i dont need this NEED1 i dont need this',
  4. 'i dont need this NEED2 i dont need this',
  5. 'i dont need this WANT THIS ALSO i dont need this',
  6. 'i dont need this ANDTHIS i dont need this',
  7. ];
  8. $searchpoz = ['NEED2', 'NEED1', 'WANT THIS ALSO','ANDTHIS'];
  9.  
  10. $matches = [];
  11. $getpositions = implode('', $getpositions); // why do we need an array?
  12. foreach($searchpoz as $val){
  13. $pos = strpos($getpositions, $val);
  14. if($pos !== false) $matches[$val] = $pos;
  15. }
  16. asort($matches);
  17. print_r(array_keys($matches));
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
Array
(
    [0] => NEED1
    [1] => NEED2
    [2] => WANT THIS ALSO
    [3] => ANDTHIS
)