0
0
PHPprogramming~15 mins

Indexed array creation in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Indexed array creation
📖 Scenario: You are creating a simple list of fruits to use in a grocery app.
🎯 Goal: Build a PHP program that creates an indexed array of fruits, adds a new fruit, and then prints the full list.
📋 What You'll Learn
Create an indexed array with exact fruit names
Add one more fruit to the array
Use a loop to access all fruits
Print the fruits in order
💡 Why This Matters
🌍 Real World
Arrays are used to store lists of items like fruits, products, or users in many web applications.
💼 Career
Knowing how to create and manipulate arrays is a basic skill for PHP developers working on websites and backend systems.
Progress0 / 4 steps
1
Create the initial indexed array
Create an indexed array called $fruits with these exact values in order: 'Apple', 'Banana', 'Cherry'.
PHP
Need a hint?

Use square brackets [] to create an indexed array in PHP.

2
Add a new fruit to the array
Add the fruit 'Date' to the end of the $fruits array using the array append syntax.
PHP
Need a hint?

Use $fruits[] = 'Date'; to add an item to the end of an indexed array.

3
Loop through the array
Use a foreach loop with variable $fruit to go through each item in $fruits.
PHP
Need a hint?

Use foreach ($fruits as $fruit) to loop through all fruits.

4
Print all fruits
Inside the foreach loop, print each $fruit followed by a newline using echo.
PHP
Need a hint?

Use echo $fruit . "\n"; to print each fruit on its own line.