<?php
$V = "Stormy";
$W = "Heavy thunderstorms";
function getMyString($SentenceSrc)
{
if ((strpos($SentenceSrc,'Heavy thunderstorms')!== true) OR (strpos($SentenceSrc,'Heavy t-storms')!== true))
$SentenceVariable = "Rains with gusty winds";
elseif ((strpos($SentenceSrc,'Sun')!== true) OR (strpos($SentenceSrc,'sun')!== true))
$SentenceVariable = "Sunny";
elseif ((strpos($SentenceSrc,'Stormy')!== true))
$SentenceVariable = "Stormy";
else
$SentenceVariable = "Partly cloudy ";
return $SentenceVariable;
}
echo getMyString($V);
echo getMyString($W);
?>
This is my code. The output should be:
StormyRains with gusty winds
But instead, it only reads the first part of the condition, and returns it True, when it is false.
my getMyString($SentenceSrc) is supposed to find a string within a given string and return a weather condition whenever the given string returns true.
strpos()!==trueis doing something, try comparing to falseOR, you should try to use||