Hello, how to insert a condition in a variable? I tried to do so

$per = "<div> ". if (1 == 1) { ."Удачно". } else { ."Не удачно". } ." </div>"; 

    2 answers 2

    Use the ternary operator:

     $per = "<div>\n" . (1 === 1 ? "Удачно" : "Не удачно") . "\n</div>"; 

    https://repl.it/Cnj3/0

    • @Sasha Osipov, replace the word Удачно with HTML pictures. And that's all. - user207618
    • @ Sasha Osipov, like this - repl.it/Cnj3/1 - user207618
    • @ Sasha Osipov, how did your code fail with an error? $post[$photo] . - user207618
    • Everything already solved the problem. - Sasha Osipov
    • and how to insert such a condition? ($_GET[id] == $iduser) OR ($type == $iduser) OR ($iduser == $idUserp) - Sasha Osipov
     $per1 = "Неудачно"; if (1 == 1) { $per1 = ."Удачно". } $per = "<div>".$per1."</div>"; 

    or

     $per = "<div>".((1 == 1)? "Удачно" : "Неудачно")."</div>"; 
    • No, it is necessary that the condition be right in Permenna - Sasha Osipov
    • "It was right in Permenny" - bother to explain what it means. - Igor
    • Copy is not good) - Sasha Osipov