Sunday, January 12, 2025
HomeProgrammingPHP Indexed Array

PHP Indexed Array

In PHP, an indexed array is a type of array where elements are assigned numeric keys automatically, starting from 0, or explicitly set by the programmer. Indexed arrays store multiple values in a single variable and are accessed using their numeric index.

See also  Power Function in Java

You can create an indexed array using the array() function or square brackets []. For example:

php

$fruits = array(“Apple”, “Banana”, “Cherry”);  

$colors = [“Red”, “Green”, “Blue”];

You can access elements by their index:

php

echo $fruits[0]; // Outputs: Apple

Indexed arrays are useful for ordered lists of data, such as names or items, and can be looped through using for or foreach.

RELATED ARTICLES
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
- Advertisment -

Most Popular

Recent Comments

0
Would love your thoughts, please comment.x
()
x