Home  >  Article  >  Backend Development  >  第一篇博文:PHP函数原型中的可选参数写法为何这么写

第一篇博文:PHP函数原型中的可选参数写法为何这么写

WBOY
WBOYOriginal
2016-06-13 12:23:30860browse

第一篇博文:PHP函数原型中的可选参数写法为什么这么写?

第一篇,算是开始吧。简单写点儿东西。

刚开始学PHP,在看PHP Manual时遇到一个问题:含可选参数的函数原型中,可选参数的写法看不懂。

例如explode函数

<span style="font-size: 14px;">array explode ( string $delimiter , string $string [, int $limit ] )</span>

可选参数都用“[方括号]”括起来,那么第三个参数$limit为可选参数。

可是为什么不这么写呢:

<span style="font-size: 14px;">array explode ( string $delimiter , string $string ,[int $limit ] )</span>

实在是无法理解这个逗号的位置。

1楼DeanChopper
可选指的是[]内的东西可有可无而不是参数,所以按你的方式无论有没有最后的参数第二个参数后面都有一个,显然这是不行的
Re: yangtoude
@DeanChopper,明白了,谢谢!
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn