Menu
Coddy logo textTech

Project Overview & Data

Part of the Fundamentals section of Coddy's PHP journey — lesson 54 of 71.

challenge icon

Challenge

Easy

In this chapter, you'll build a simple to-do list manager using arrays.

Read three lines of input, each containing a task description (e.g., Buy groceries).

Create a $todos array containing three task arrays. Each task should be an associative array with:

  • "task" - the task description from input
  • "completed" - set to false for all tasks

Then print:

  1. The task description of the first task
  2. The task description of the second task
  3. The total number of tasks in the list

Print each result on a separate line.

Example:

If the inputs are Buy groceries, Walk the dog, and Finish homework, the output should be:

Buy groceries
Walk the dog
3

If the inputs are Clean room, Call mom, and Read book, the output should be:

Clean room
Call mom
3

Try it yourself

<?php
// Read three task descriptions
$task1 = trim(fgets(STDIN));
$task2 = trim(fgets(STDIN));
$task3 = trim(fgets(STDIN));

// TODO: Write your code below
// Create a $todos array containing three task arrays
// Each task should be an associative array with "task" and "completed" keys

// Output the first task description

// Output the second task description

// Output the total number of tasks
?>

All lessons in Fundamentals