--- title: Arrays --- ## Arrays Arrays are like regular variables, but hold multiple values in an ordered list. This can be useful if you have multiple values that are all related to each other, like a list of student names or a list of capital cities. ### Types Of Arrays In PHP, there are two types of arrays: Indexed arrays and Associative arrays. Each has their own use and we'll look at how to create these arrays. ### Indexed Array Example An indexed array is a list of ordered values. Each of these values in the array is assigned an index number. Indexes for arrays always start at `0` for the first value and then increase by one from there. ```PHP 83, "Frank" => "93", "Benji" => "90"); ``` `$student_scores['Joe']` would return `83`, `$student_scores['Frank']` would return `93`, `$student_scores['Benji']` would return `90`. ### Multidimensional Array Example A multidimensional array is an array that contains other arrays. This lets you create complex data structures that can model a very complex group of data. ```PHP "Joe", "score" => 83, "last_name" => "Smith"), array("first_name" => "Frank", "score" => 92, "last_name" => "Barbson"), array("first_name" => "Benji", "score" => 90, "last_name" => "Warner") ); ``` Now you can get the first student's `first_name` with: ```PHP $students[0]['first_name'] ``` #### More Information: * php.net arrays manual