William
William

Reputation: 749

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

What is this syntax I've seen some documentations applying, for example:

Jquery Sizzle

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

Codeiginiter 3

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

Upvotes: 5

Views: 142

Answers (2)

SYNCRo
SYNCRo

Reputation: 470

Those parentheses show that those parameters are optional in syntax. This examples aren't code lines, but syntax.

Valid code lines:

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

But, if we take a look at @taxicala answer we have another situation

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

Valid code lines are

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

but not

foo($param, $param2)

Upvotes: 1

taxicala
taxicala

Reputation: 21759

Basically, what this means, is that all parameters inside the [] are optional. You dont need to pass anything in order to make the function call work:

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

$param1 and $param2 are optional, $param is mandatory.

Upvotes: 6

Related Questions