O
O
onlinejunior2020-06-20 19:54:53
go
onlinejunior, 2020-06-20 19:54:53

Is there a similar php function in GO?

For example in go: in php:
if bool {//true} else {//false}


$s = bool ? "true" : "false";

Answer the question

In order to leave comments, you need to log in

3 answer(s)
M
Maxim Fedorov, 2020-06-20
@onlinejunior

The answer to this question is on the Go site: Why does Go not have the ?: operator?
In short - the authors believe that this is better

T
Tenegorn, 2020-07-04
@Tenegorn

Alternatively, you can use.

func ternary(condition bool, iftrue, iffalse interface{}) interface{} {
  if condition {
    return iftrue
  } else {
    return iffalse
  }
}

[
[email protected]&a qkcUv*6=KygEm, 2020-06-20
@KrasPvP

there really is no ternary operator, but you can use this switch:

switch {
    case Exp: return "true"
    default: return "false"
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question