모든 작업 표시
Coddy PHP 여정의 기초 섹션에 포함된 레슨 — 71개 중 56번째.
챌린지
쉬움이전 레슨에서 $todos 배열에 새 작업을 추가했습니다. 이제 모든 작업을 형식화된 목록으로 표시하는 기능을 추가하세요.
작업 설명을 위한 네 줄의 입력을 읽으세요 (이전 레슨처럼 초기 세 작업과 하나의 새 작업).
네 개의 모든 작업으로 $todos 배열을 만든 후, 배열을 순회하며 각 작업을 다음 형식으로 출력하세요:
- [task description] (Pending)모든 작업의 "completed"가 false로 설정되어 있으므로, 각 작업은 설명 뒤에 (Pending)을 표시해야 합니다.
각 작업을 별도의 줄에 출력하세요.
예시:
입력값이 Buy groceries, Walk the dog, Finish homework, 그리고 Call mom인 경우, 출력은 다음과 같아야 합니다:
- Buy groceries (Pending)
- Walk the dog (Pending)
- Finish homework (Pending)
- Call mom (Pending)입력값이 Clean room, Read book, Exercise, 그리고 Cook dinner인 경우, 출력은 다음과 같아야 합니다:
- Clean room (Pending)
- Read book (Pending)
- Exercise (Pending)
- Cook dinner (Pending)직접 해보기
<?php
// 세 개의 작업 설명을 읽습니다
$task1 = trim(fgets(STDIN));
$task2 = trim(fgets(STDIN));
$task3 = trim(fgets(STDIN));
// 추가할 새 작업을 읽습니다
$newTask = trim(fgets(STDIN));
// 세 개의 작업 배열을 포함하는 $todos 배열을 생성합니다
// 각 작업은 "task"와 "completed" 키를 가진 연관 배열이어야 합니다
$todos = [
["task" => $task1, "completed" => false],
["task" => $task2, "completed" => false],
["task" => $task3, "completed" => false]
];
// 배열의 끝에 새 작업을 추가합니다
// 배열을 순회하며 형식화된 목록으로 각 작업을 출력합니다
?>기초의 모든 레슨
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 Types3Basic Operators
Arithmetic OperatorsModulo OperatorExponentiation OperatorCombined AssignmentIncrement/DecrementOperator PrecedenceRecap - Simple CalculationsString Operators