Advertisement
basart1

Untitled

Mar 16th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2. $arraystring = ['cat','google','test','catty', 'meow'];
  3. $substring = 'at';
  4. filter($arraystring,$substring);
  5. function filter ($arraystring,$substring){
  6.     $resultarray = array();
  7.     foreach ($arraystring as  $substringword) {
  8.         $checkSubstring = sub($substringword,$substring);
  9.         if ($checkSubstring){
  10.             $resultarray[] = $substringword;
  11.         }
  12.     }
  13.  
  14.     return $resultarray;
  15. }
  16.    
  17. function sub($substringword,$substring){
  18.     for ($i = 0; $i <strlen($substringword); $i++) {
  19.                     $checkResult = 0;
  20.         for ($j = 0;$j < strlen($substring);$j++){
  21.             if ($substringword[$i + $j] === $substring[$j])  {
  22.                 $checkResult++;
  23.                 if ($checkResult == strlen($substring)) {
  24.  
  25.                     return true;
  26.                 }
  27.  
  28.             }
  29.         }
  30.     }
  31.         return false;
  32. }
  33. var_dump(filter($arraystring,$substring));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement