0
0
PHPprogramming~15 mins

Array push and pop in PHP - Mini Project: Build & Apply

Choose your learning style9 modes available
Array push and pop
📖 Scenario: You are managing a simple list of tasks for your daily routine. You want to add new tasks and remove completed tasks using PHP arrays.
🎯 Goal: Build a PHP script that starts with a list of tasks, adds a new task to the list, removes the last task, and then shows the final list.
📋 What You'll Learn
Create an array called tasks with three specific tasks
Add a new task to the tasks array using array_push
Remove the last task from the tasks array using array_pop
Print the final tasks array using print_r
💡 Why This Matters
🌍 Real World
Managing lists of tasks, items, or data is common in many programs. Adding and removing items from arrays helps keep data organized and up to date.
💼 Career
Understanding how to manipulate arrays is essential for backend development, scripting, and working with data structures in PHP.
Progress0 / 4 steps
1
Create the initial tasks array
Create an array called tasks with these exact values: 'Buy groceries', 'Clean the house', and 'Pay bills'.
PHP
Need a hint?

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

2
Add a new task to the array
Use array_push to add the task 'Walk the dog' to the tasks array.
PHP
Need a hint?

Use array_push with the array name and the new task as arguments.

3
Remove the last task from the array
Use array_pop to remove the last task from the tasks array.
PHP
Need a hint?

Call array_pop with the array name to remove the last item.

4
Print the final tasks array
Use print_r to display the final tasks array.
PHP
Need a hint?

Use print_r($tasks); to show the array content.