I am new to php
, so don't know much. I the php DOCS for example fwrite
:
int fwrite ( resource $handle , string $string [, int $length ] )
what does [
and ]
denote ? I see them everywhere. What do they stand for ?
I am new to php
, so don't know much. I the php DOCS for example fwrite
:
int fwrite ( resource $handle , string $string [, int $length ] )
what does [
and ]
denote ? I see them everywhere. What do they stand for ?
It means that the parameter is optional. There’s usually a default specified after the parameter name using = (default)
, and details down in the description.
In the case of fwrite
, that’s:
If the length argument is given, writing will stop after length bytes have been written or the end of string is reached, whichever comes first.
It means optional arguments to the method, you don't have to pass them.
Generally, there is a default shown, for example in the case of preg_quote
, the default is NULL:
string preg_quote ( string $str [, string $delimiter = NULL ] )
If you're happy with that default, you can omit the argument. Another good example would be mktime
.
int mktime ([ int $hour = date("H") [, int $minute = date("i") [, int $second = date("s") [, int $month = date("n") [, int $day = date("j") [, int $year = date("Y") [, int $is_dst = -1 ]]]]]]] )
Note that in mktime
's documentation, it's stated that you can skip parameters using a specific format:
Arguments may be left out in order from right to left; any arguments thus omitted will be set to the current value according to the local date and time.
It stands for an optional argument. If you don't specify it, default value will be used. It will say in the documentation which one it is, depending on the function.
Sometimes you will want to pass optional parameters to a function, for example if you want to trim all slashes on the right, you can pass optional argument to the function
$string = rtrim($string, '/');
Without optional parameter '/'
, whitespace would be trimmed
It means it's an optional parameter.