'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');


Solution 1:[1]

You can assign the variable inside the ternary:

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Barmar