Update index.md to add a new item into php array (#31333)

This commit is contained in:
Daniele Pedone
2018-12-17 06:06:35 +01:00
committed by Randell Dawson
parent 68c5a2e4e8
commit 6d9f8593cb

View File

@ -84,6 +84,33 @@ Would produce the following output:
I like Yamaha
```
## Add Item
Is possible to add any item to an existing array.
An example of addition can be seen below:
```
<?php
$bikes = array('Suzuki', 'BMW');
$bikes[] = 'Yamaha';
```
Another example, using named keys can be seen below:
```
<?php
$bikes = [
'favorite' => 'Suzuki',
'second favorite' => 'BMW'
];
$bikes['not my favorite'] = 'Yamaha';
```
## Multidimensional Array
As we mentioned earlier arrays are collection of items, often times these items may be arrays of themselves.
@ -92,7 +119,6 @@ As we mentioned earlier arrays are collection of items, often times these items
You will always be able to get the value for the specific key by going down the layers: $arr['layerOne']['two']
## Pitfalls
When working with arrays, there are a few important things to keep in mind: