Locked lesson.
About this lesson
Exercise files
Download this lesson’s related exercise files.
Arrays.docx58.9 KB Arrays - Solution.docx
59.1 KB
Quick reference
Arrays
Arrays are containers that hold many things.
When to use
An array is a container, like a variable. But unlike a variable, arrays hold many things at once.
Instructions
There are a couple of different arrays (indexed arrays and associative arrays).
Items in Indexed arrays are numbered, starting with zero.
$pizza_toppings = array("pepperoni", "cheese", "onion");
echo $pizza_toppings[1]; // will list "cheese"
Items in Associative arrays are key and value pairs.
$ages = array("John"=>"39", "Tim"=>"42", "Mary"=>"29");
echo $age["John"];
Hints & tips
- Arrays are containers that hold many things
- They hold strings, numbers, variables, other arrays, and more
- Indexed arrays use numbers
- Associative arrays use key/value pairs
- Items in an Array are numbered, starting with zero.
Lesson notes are only available for subscribers.