Project Overview & Data
Part of the Fundamentals section of Coddy's PHP journey — lesson 54 of 71.
Challenge
EasyIn 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 tofalsefor all tasks
Then print:
- The task description of the first task
- The task description of the second task
- 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
3If the inputs are Clean room, Call mom, and Read book, the output should be:
Clean room
Call mom
3Try 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
4Comparison & Logical Operators
Comparison OperatorsEquality & IdentityLogical Operators Part 1Logical Operators Part 2Recap - Simple Logic2Variables and Data Types
NumbersStrings and QuotesBooleansNaming ConventionsRecap - Variable InitEmpty VariablesString ConcatenationGetting User InputCast to Different Types5Conditional Logic
If StatementIf - ElseThe Ternary OperatorNull Coalescing OperatorSwitch StatementRecap - Making Decisions3Basic Operators
Arithmetic OperatorsModulo OperatorExponentiation OperatorCombined AssignmentIncrement/DecrementOperator PrecedenceRecap - Simple CalculationsString Operators6Arrays Part 1 - Indexed
Introduction to ArraysCreating Indexed ArraysAccessing Elements by IndexModifying Elements by IndexArray Size with CountAdding Elements to an ArrayRecap - Managing a Simple List9Project: Simple To-Do List
Project Overview & DataAdding a New Task