Learn
Ordered Arrays
Review

We covered a lot in this lesson! Great job. Take a second to review everything you learned:

  • Arrays are ordered collections of data that are a type of data structure fundamental to computer science.
  • In PHP, we refer to this data structure as ordered arrays.
  • The location of an element in an array is known as its index.
  • The elements in an ordered array are arranged in ascending numerical order starting with index zero.
  • We can construct ordered arrays with a built-in PHP function: array().
  • We can construct ordered arrays with short array syntax, e.g. [1,2,3].
  • We can print arrays using the built-in print_r() function or by converting them into strings using the implode() function.
  • We use square brackets ([]) to access elements in an array by their index.
  • We can add elements to the end of an array by appending square brackets ([]) to an array variable name and assigning the value with the assignment operator (=).
  • We can change elements in an array using array indexing and the assignment operator.
  • The array_pop() function removes the last element of an array.
  • The array_push() function adds elements to the end of an array.
  • The array_shift() function removes the first element of an array.
  • The array_unshift() function adds elements to the beginning of the array.
  • We can use chained square brackets ([]) to access and change elements within a nested array.

Instructions

We provided some example code for each of the core concepts covered in this lesson. Feel free to play around with the code to practice or experiment!

Folder Icon

Take this course for free

Already have an account?