Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $arraystring = ['cat','test','catty', 'meow'];
- $substring = 'c';
- filter($arraystring,$substring);
- function filter ($arraystring,$substring){
- $resultarray = array();
- foreach ($arraystring as $substringwords) {
- $checkSubstring = sub($substringwords,$substring);
- if ($checkSubstring){
- $resultarray[] = $substringwords;
- } else {
- echo $substring. " "."not found in"." ".$arraystring;
- }
- }
- return $resultarray;
- }
- function sub($substringwords,$substring){
- $array = array();
- $indexofarray = 0;
- for ($i = 0; $i <strlen($substringwords); $i++) {
- for ($j = 0;$j < strlen($substring);$j++){
- if ($substringwords[$i] == $substring[$j]) {
- $array[] = $substring;
- $indexofarray++;
- }
- }
- }
- if (empty($array)) {
- return false;
- } else {
- return true ;
- }
- }
- var_dump(filter($arraystring,$substring));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement