EvandroPH
EvandroPH

Reputation: 21

PHP Using a Ternary Result inside the result

I need use a ternary conditional result inside my called function. Is this possible?

(new SaveData($query))->idSaved() ? letsgo('gotrue', idSaved()) : letsgo('gofalse');

It's possible use result of my ternary inside that? In this case, idSaved() return the Inserted ID on my database.

Actually I use:

$res = new SaveData($query);
$res->idSaved() ? letsgo('gotrue', $res->idSaved()) : letsgo('gofalse');

Upvotes: 1

Views: 39

Answers (1)

Barmar
Barmar

Reputation: 781716

You can assign the variable inside the ternary:

($res = (new SaveData($query))->idSaved()) ? letsgo('gotrue', $res) : letsgo('gofalse')

Upvotes: 1

Related Questions