I am a learner in PHP, and I have a code in which I am implementing HTML5 code. What I am trying to do is to embed the inline ternary operator in my placeholder.
I have followed this link, but none of them are having same problem statement:
My Code:
echo "<input type='text' class='form-control' value='".$value."' placeholder='HERE I WANT TO OPERATE'>";
Tried: I have tried this in my code, but I am getting errors
echo "<input type='text' class='form-control' value='".$value."' placeholder='"empty($value) ? 'Some Text' : 'Enter Data';"'>";
I know how to do the ternary operation outside the echo code
in PHP, but I am looking for this way.
Advertisement
Answer
The ternary operation will return a string. As such, it has to be concatenated to the rest of the string.
echo "<input type='text' class='form-control' value='".$value."' placeholder='". (empty($value) ? 'Some Text' : 'Enter Data') ."'>";