0
0
PHPprogramming~15 mins

Array count and length in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Array count and length
📖 Scenario: You are managing a small online store. You have a list of products in an array. You want to find out how many products are in the list.
🎯 Goal: Learn how to create an array, set a variable for counting, use the count() function to find the number of items in the array, and print the result.
📋 What You'll Learn
Create an array called products with these exact items: 'Apple', 'Banana', 'Orange', 'Mango'
Create a variable called totalProducts to store the count of items in the products array
Use the count() function with the products array to get the number of items
Print the value of totalProducts exactly as an integer
💡 Why This Matters
🌍 Real World
Counting items in a list is common in online stores, inventory systems, and any place where you manage collections of things.
💼 Career
Knowing how to count array items helps you handle data collections efficiently, a key skill for web developers and programmers.
Progress0 / 4 steps
1
Create the products array
Create an array called products with these exact items: 'Apple', 'Banana', 'Orange', 'Mango'
PHP
Need a hint?

Use square brackets [] to create the array and separate items with commas.

2
Create the totalProducts variable
Create a variable called totalProducts and set it to 0 as a starting point
PHP
Need a hint?

Use $totalProducts = 0; to create the variable.

3
Count the number of products
Use the count() function with the products array and assign the result to the variable totalProducts
PHP
Need a hint?

Use count($products) to get the number of items in the array.

4
Print the total number of products
Write a print statement to display the value of totalProducts
PHP
Need a hint?

Use print($totalProducts); to show the number.