Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP question mark operator and string concatenation

I'm still a newbie in php and I'm using codeigniter for my backend framework. I have a table.php file that will generate a html table in real-time. Then, I encounter some issues.

$output_string .= "<td>".($row->isactive == "0") ? "Activated":"Deactivated"."</td>";

with the above code I get nothing, but with a little change to:

$isactive = ($row->isactive == "0") ? "Activated":"Deactivated";
$output_string .= "<td>".$isactive."</td>";

I get my results, so my question is, why?

Doesn't PHP support question mark operator in string concatenation??

like image 316
Jerry Lam Avatar asked Mar 13 '26 18:03

Jerry Lam


1 Answers

It does support it, just put some parenthesis around it:

$output_string .= "<td>".(($row->isactive == "0") ? "Activated":"Deactivated")."</td>";
like image 100
Matt Dodge Avatar answered Mar 15 '26 07:03

Matt Dodge



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!