practice questions on PHP Arrays

🧠 ✅ Level 1: Basic (Indexed Arrays)

🔹 Q1

Create an indexed array of 5 fruits and print all values.


🔹 Q2

Print the second element of an array:

$colors = ["Red", "Green", "Blue", "Yellow"];

🔹 Q3

Count total elements in an array and print the result.


🔹 Q4

Loop through an array using for loop and display all values.


🔹 Q5

Create an array of numbers and print only numbers greater than 10.


🧠 ✅ Level 2: Associative Arrays

🔹 Q6

Create an associative array of a student:

  • name
  • age
  • course
    Print all values.

🔹 Q7

Loop through associative array using foreach and print:

key = value

🔹 Q8

Find the highest value in this array:

$marks = ["Math" => 80, "Science" => 90, "English" => 75];

🔹 Q9

Check if a key exists in an array.


🔹 Q10

Update a value in associative array (change age).


🧠 ✅ Level 3: Multidimensional Arrays

🔹 Q11

Create a multidimensional array of 3 students:
(name, age, course)


🔹 Q12

Print all student names using loop.


🔹 Q13

Print details in this format:

Aditya - BCA
Rahul - BSc

🔹 Q14

Find the student with highest age.


🧠 ✅ Level 4: Array Functions

🔹 Q15

Sort an array in ascending order.


🔹 Q16

Sort an array in descending order.


🔹 Q17

Merge two arrays and print result.


🔹 Q18

Filter even numbers using array_filter().


🔹 Q19

Square all numbers using array_map().


🔹 Q20

Remove duplicate values from array.


🚀 ✅ Bonus (Important for Projects)

🔹 Q21

Create a simple search system:

  • Array of names
  • User inputs a name
  • Check if it exists

🔹 Q22

Create a marks calculator:

  • Store marks in array
  • Calculate total and average

🔹 Q23

Create a shopping cart system (basic):

  • Add items to array
  • Display all items

🎯 Challenge Questions (Advanced)

🔹 Q24

Sort associative array by values descending.


🔹 Q25

Convert this array:

["a", "b", "c"]

into:

["a" => 1, "b" => 2, "c" => 3]

🔹 Q26

Group numbers into:

  • Even array
  • Odd array

🔹 Q27

Find duplicate values in an array.


🔹 Q28

Flatten a multidimensional array into a single array.


💡 Teaching Tip

Give students:

  • 🟢 Level 1–2 → Beginners
  • 🟡 Level 3–4 → Intermediate
  • 🔴 Bonus + Challenge → Advanced