Syntax of Functions in PHP manual

58 Views Asked by At

I have hard time understanding the syntax of the following function (and others alike):

int fwrite ( resource $handle , string $string [, int $length ] )

what is the meaning of the brackets and comma that follows [, int $length ]. what it should indicate?

3

There are 3 best solutions below

0
On BEST ANSWER

The the following example:

int fwrite ( resource $handle , string $string [, int $length ] )
  1. The first int represents the data type returned by the function
  2. The expected datatype of each parameter precedes the parameter name
  3. The square brackets indicate optional parameters i.e. the parameters that you can omit
  4. An optional parameter might be followed by a = <some value> indicating the default value that is used if you omit that parameter
0
On

It's simply an optional parameter.

0
On

[, int $length] indicates an optional parameter you may add when you use the comfort function fwrite. Moreover, it also tells you that it has to be an integer.