How to pass a ternary operator to conditional if in php?

0

I recently had a Ternary operation that is copied here below,

variable1 += (variable1.length < 1 ? "  " : '|') +(array_varible1[elemento_for].length >0 ? array_varible1[elemento_for] : " ");

It works perfectly and does everything I'm asking for, but as I was doing it I realized that it is a simplified conditional if, I would like to know if someone can translate this Ternary operator to an if condition.

Thanks guys.

    
asked by gama984 30.10.2018 в 20:57
source

1 answer

1

would be something like this:

$variable1 =""


if(variable1.length < 1){
 $variable1 += " ";

}else{
 $variable1 +='|';
}

if(array_varible1[elemento_for].length >0)
{
    $variable1 +=array_varible1[elemento_for];

} else{
    $variable1 +=" "
}

the symbols? it is a conditional and the following to the symbol will be executed if it is true, while the ones that are after the: would be executed if the condition is a false example:

 echo 1==1 ? "si" : "no";
    
answered by 30.10.2018 / 21:04
source