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