PHP Array

Tan 26-10-2016

An array in PHP is actually an ordered map.
A map is a type that associates values to keys.
This type is optimized for several different uses; it can be treated as an array, list (vector), hash table (an implementation of a map), dictionary, collection, stack, queue, and probably more.

1. Creating Arrays

An array can be created using the array() language construct. It takes any number of comma-separated key => value pairs as arguments.

array(key => value,key2 => value2,key3 => value3, ...)
array(value, value2,value3, ...)

You can also create an array by making individual value assignments into the array variable name
$students[] = 'Johnson';

2. Referencing Sequential Array Items

To reference individual array items, use an array name and index pair

3. Changing arrays values

scores = array(75, 65, 85, 90);
scores[3] = 95;