Why do some array parameters have a comma after opening parentheses?

What is this syntax? I saw some documents, for example:

Jquery sizzle

Sizzle( String selector[, DOMNode context[, Array results]] )

Codeiginiter 3

set_userdata($data[, $value = NULL])

+5
source share
2 answers

Basically, this means that all parameters inside [] are optional. You do not need to skip anything to make the function call work:

 foo($param [, $param2 = NULL, $param3 = 1]) 

$param1 and $param2 are optional, the $ param parameter is required.

+6
source

These brackets indicate that these parameters are optional in syntax. These examples are not lines of code, but syntax.

Valid lines of code:

 Sizzle(selector, context, results); Sizzle(selector, context); Sizzle(selector); set_userdata($data, $value); set_userdata($data); 

But, if we look at @taxicala's answer, we will have a different situation.

 foo($param [, $param2 = NULL, $param3 = 1]) 

Valid lines of code

 foo($param, $param2, $param3) foo($param) 

but not

 foo($param, $param2) 
+1
source

All Articles