mercredi 7 février 2018

PHP if first var is empty use second one

I have so a little question if it possible to check with a variable if one of to var are not empty and to use their value? Like this:

    $var1="";
    $var2="123";

    $varifnotempy= $var1||$var2;

    echo $varifnotempy;

here i want not 2 because he give me wich one is not empty but i want that he returns me 123 and if $var1 is not null than to use the value of $var1

I know that i can use if else but i want to know if it possible to make it by variable. Thx.

Aucun commentaire:

Enregistrer un commentaire