user3386779
user3386779

Reputation: 7175

ternary operator for a variable

I have a date field which returns '1970-01-01' for empty value. So I want to create a ternary operator for a variable $from.Still it returns 1970-01-01.What I did wrong

$from=$asset_other_details->start_date;  //1970-01-01
$from == '1970-01-01' ? '' : $from ;

Upvotes: 0

Views: 333

Answers (2)

Death-is-the-real-truth
Death-is-the-real-truth

Reputation: 72299

You have to assign new values to $form based on the comparison output like below:-

$from = $asset_other_details->start_date;  //1970-01-01
$from = ($from == '1970-01-01') ? '' : $from ;

Output to understand:- https://eval.in/867743

Upvotes: 8

mega6382
mega6382

Reputation: 9396

you are not assigning the $from the new value. Try the following:

$from = ($asset_other_details->start_date == '1970-01-01') ? '' : $asset_other_details->start_date;

Upvotes: 1

Related Questions