unable to understand php online manual

孤者浪人 提交于 2019-12-13 22:15:12

问题


I was trying to find help from the PHP manual (http://de2.php.net/manual/en/function.array-multisort.php) but the description syntax for parameters is too complex, like

  bool array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC [, mixed   $array1_sort_flags = SORT_REGULAR [, mixed $... ]]] )

I know that the parameters are there described, like:

array1

An array being sorted.

array1_sort_order

The order used to sort the previous array argument. Either SORT_ASC to sort ascendingly or SORT_DESC to sort descendingly.

but what's the meaning of that description and square brackets?


回答1:


In the description square brackets indicate optional parameters.

So with something like the following:

bool array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC [, mixed   $array1_sort_flags = SORT_REGULAR [, mixed $... ]]] )

if you break things down you have:

bool array_mult...

1) bool indicates that the type returned is boolean

bool array_multisort ( array &$array1...

2) array &$array1 indicates that the first parameter must be an array and that the array is taken by reference (in other words the array that you pass as parameter will be directly modified by the function)

bool array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC...

3) [, mixed $array1_sort_order = SORT_ASC means that there could be an optional second parameter, the type is not forced to a specific type (an array or a non array are both accepted) and the default value is the constant SORT_ASC

bool array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC [, mixed $array1_sort_flags = SORT_REGULAR...

4) [, mixed $array1_sort_flags = SORT_REGULAR is another optional field that could be specified if the previous one (3) is specified (in fact it is under the same square bracket). As previously mixed implies that the type is not mandatory and there is a default value (SORT_REGULAR).

bool array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC [, mixed   $array1_sort_flags = SORT_REGULAR [, mixed $... ]]] )

5) Finally, [, mixed $... ], the inner square bracket, is an optional parameter available if you specified the other two, and implies that you can have more parameters following the same path as the previous ones (2, 3 and 4) to specify more arrays, orders and flags.




回答2:


The parameters between brackets are optional parameters

I will explain a little to clarify:

bool array_multisort ( array &$array1 [, mixed $array1_sort_order = SORT_ASC [, mixed   $array1_sort_flags = SORT_REGULAR [, mixed $... ]]] )

Params:

  • array &$array1: This is the first paramter and is obligatory (not in square brackets), and is the array you want to sort.

  • mixed $array1_sort_order = SORT_ASC: The second parameter, this is sort order and is an optional parameter, if you don't specify then the default value is SORT_ASC

And so on...



来源:https://stackoverflow.com/questions/24386569/unable-to-understand-php-online-manual

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!