Advanced Arrays
Review of Arrays

Arrays are a useful way to store multiple values, like numbers, strings, and even other arrays:

$myArray = array(1, 2, 3);

Here we create an array of three numbers. Remember that array positions start from 0; therefore to access the third item in this array, we type:

  1. On line 8, set $fruits equal to an array of three strings: 'bananas', 'apples' and 'pears'.
  2. Modify the echo statement on line 9 to display the fruit in the middle of the array (that is, it should echo "apples".
Stuck? Get a hint! Hint
Get live, fast support from Codecademy Advisors when you get stuck. Learn more.

The array you created has 3 values (and PHP starts counting from 0), so you would display the middle (or "second") value by adding $fruits[1] to the echo statement.

View Preview