I want to set the default value for a variable, change this value when the input is committed.
Method: Use "?:" Conditional sentence test user's input value:
PHP
$ filename = isset ($ argv [1])? $ argv [1]: "php: // stdin"
?>
The above code is equivalent to:
PHP
IF (isset (Argv [1])) {
$ filename = $ argv [1];
} else {
$ filename = "php: // stdin";
}
?>
From the two code, it can be seen that the three-yuan operator (?:) Has greatly reduced the time of programmer development. Therefore, it also has "syntax condiments"!