Use of strings --- Trim operator

zhaozj2021-02-16  101

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:

$ filename = isset ($ argv [1])? $ argv [1]: "php: // stdin"

?>

The above code is equivalent to:

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"!

转载请注明原文地址:https://www.9cbs.com/read-11193.html

New Post(0)