Subscriber only lesson.
Sign up to this course to view this lesson.
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.
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; // will list "cheese"
Items in Associative arrays are key and value pairs.
$ages = array("John"=>"39", "Tim"=>"42", "Mary"=>"29");
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.