Answer the question
In order to leave comments, you need to log in
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
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
Alternatively, you can use.
func ternary(condition bool, iftrue, iffalse interface{}) interface{} {
if condition {
return iftrue
} else {
return iffalse
}
}
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 questionAsk a Question
731 491 924 answers to any question