Home >Backend Development >PHP Tutorial >Why are the square brackets of optional parameters of functions in the thinkphp manual an inclusive relationship?
For example:
<code>int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )</code>
Why are the optional parameters in square brackets written like this:
For example, the first optional parameter array &$matches has a [,
Why is the previous parameter added in the background?
In addition, the way it is written in the manual gives the impression that:
$matches includes $flags, and $flags includes $offset
Why is it written like this?
Is there really an inclusive relationship between these parameters?
For example:
<code>int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )</code>
Why are the optional parameters in square brackets written like this:
For example, the first optional parameter array &$matches has a [,
Why is the previous parameter added in the background?
In addition, the way it is written in the manual gives the impression that:
$matches includes $flags, and $flags includes $offset
Why is it written like this?
Is there really an inclusive relationship between these parameters?
is better understood as an optional dependency. For example, flags
is an optional dependency of matches
. That is to say, when you provide the matches
parameter, you can choose to provide flags
to match matches
Working together, that is, without matches
, individual flags
will have no effect.