mardi 15 novembre 2016

Do a OR in PHP Variable?

I seen it around and not sure if it was in JS or PHP but if it was possible in PHP that would be great! If not, how would i go about it without a IF, if not possible without one then how do i go about it with one?

Code:

$myvar = str_replace("hello","jpg",$myvar) || str_replace("hi","gif",$myvar); //Didnt work

And i tried:

$myvar = (str_replace("hello","jpg",$myvar) || str_replace("hi","gif",$myvar)); //Didnt work

Basically what i am trying to achieve here is to run whatever one that comes back true. If it cant do: str_replace("hello","jpg",$myvar) then do str_replace("hi","gif",$myvar). Now i tried doing a IF but that also didnt work.

My IF that also didnt work:

if (str_replace("hello","jpg",$myvar) == true)
{
    $myvar = str_replace("hello","jpg",$myvar);
}
else if (str_replace("hi","gif",$myvar) == true)
{
    $myvar = str_replace("hi","gif",$myvar);
}

Aucun commentaire:

Enregistrer un commentaire