Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reading and understanding the PHP manual description

Tags:

php

I am currently going through the PHP manual and I am having a problem reading the description. For example on this array_slice method description:

array array_slice ( array $array , int $offset [, int $length = NULL [, bool $preserve_keys = false ]] )

or maybe a simple one of substr:

string substr ( string $string , int $start [, int $length ] )

I do not understand the [, that comes after $offset and NULL. Where can I read on this or what does the [, mean and how do you read it?

like image 557
Zack Avatar asked Nov 01 '22 08:11

Zack


1 Answers

The [ ] usually show optional parameters. So the [, is saying you could, but don't have to do array_slice($array, $offset, $length) the $length parameter is optional.

You could only do array_slice($array, $offset).

like image 148
Mikolaj Avatar answered Nov 15 '22 04:11

Mikolaj