Advertisement
basart1

Untitled

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