I have a string that I want to append it some other string. let’s say:
$my_string = 'Hello';
$my_string .= ' there';
this would return ‘Hello there’.
I want to make this conditional like this:
$my_string = 'Hello';
$append = 'do';
if ( $append == 'do' ) {
$my_string .= ' there';
}
Now, I want to use a ternary operation to do this, but all the examples I came across are for if/else which will be something like:
$my_string .= ( $append == 'do' ) ? ' there' : '';
so is it possible to do it with only IF and without else?
No… ternary means three parts you need the condition, the true part, and the false part