Back to Developer Roadmap

Indexed Arrays

src/data/roadmaps/php/content/[email protected]

4.0807 B
Original Source

Indexed Arrays

Indexed arrays in PHP store values that are accessed through numerical indexes, which start at 0 by default. This might be particularly useful when you have a list of items in a specific order. For example, you might use an indexed array to represent a list of your favorite books, where each book is numbered starting from 0. Each individual item in the array, book in this case, can be accessed by their specific index. You can use the array() function or the short array syntax [] to declare an indexed array.

Here's an Example:

$books = ["The Great Gatsby", "Moby Dick", "To Kill a Mockingbird"];
echo $books[0]; //Outputs "The Great Gatsby"

Visit the following resources to learn more: