Arrays and functions

Lists, associative arrays and your own functions.

About 4 hours of study

Learning objectives

Lessons

  1. 1

    Arrays

    Lists of values: indexes, adding and removing items, sorting, searching and tables made of arrays.

  2. 2

    Associative arrays

    Arrays with names as keys: reading and changing pairs, safe reads, sorting by key or value, counting and records.

  3. 3

    Functions

    Writing your own functions: parameters, return values, types, defaults, named arguments, references and recursion.

Module practice

Module quiz

1. What is the index of the first item of an array?
2. Which function counts the items of an array?
3. Which function sorts by value from big to small and keeps the keys?
4. How do you read $ages["Zed"] safely, with 0 when it is missing?
5. What does a function return when it has no return statement?
6. What does the ampersand in function add(int &$n) do?

‹ Input, decisions and loopsClosures, built-in functions and objects ›