Heim  >  Artikel  >  Backend-Entwicklung  >  thinkphp手册中函数的可选参数的中括号为什么是包含的关系?

thinkphp手册中函数的可选参数的中括号为什么是包含的关系?

WBOY
WBOYOriginal
2016-09-21 14:12:571111Durchsuche

比如:

<code>int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )</code>

中括号内的可选参数,为什么是这样写的:
比如第一个可选参数array &$matches 的前一个参数后台加了个[,
为什么加上前面那个参数去了?

另外,手册中这样的写法,给人的感觉是:
$matches包括$flags,而$flags包含$offset
为什么要这样写?

这些参数之间,真的存在包含的关系吗?

回复内容:

比如:

<code>int preg_match ( string $pattern , string $subject [, array &$matches [, int $flags = 0 [, int $offset = 0 ]]] )</code>

中括号内的可选参数,为什么是这样写的:
比如第一个可选参数array &$matches 的前一个参数后台加了个[,
为什么加上前面那个参数去了?

另外,手册中这样的写法,给人的感觉是:
$matches包括$flags,而$flags包含$offset
为什么要这样写?

这些参数之间,真的存在包含的关系吗?

理解成可选的依赖关系会比较好,例如flagsmatches的可选依赖,也就是说,当你提供matches参数时,你可以选择提供flags来和matches一起工作,也就是说,没有matches,单独的flags也就没作用了。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn