Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $mystring = "red blue balloon";
- $matches = null;
- preg_match_all('/(red|blue|balloon)/uim', $mystring, $matches, PREG_OFFSET_CAPTURE);
- $counts = $matches[0];
- $red = 0;
- $blue = 0;
- $ballon = 0;
- foreach ($counts as $count){
- if($count[0] == "red"){
- $red += 1;
- } else if($count[0] == "blue"){
- $blue += 1;
- } else if($count[0] == "balloon"){
- $ballon += 1;
- }
- }
- $output = [
- "red" => $red >= 1,
- "blue" => $blue >= 1,
- "red and blue" => $red >= 1 && $blue >= 1
- ];
- print_r($output);
Advertisement
Add Comment
Please, Sign In to add comment