Event Data
Part of the Logic & Flow section of Coddy's PHP journey — lesson 59 of 68.
Challenge
EasyYou will receive one input: a JSON string representing an array of events. Each event is an associative array with three keys: "name" (the event name), "date" (in YYYY-MM-DD format), and "location" (the event location).
The input will look like this: [{"name":"Team Meeting","date":"2024-04-15","location":"Office"},{"name":"Conference","date":"2024-05-20","location":"Convention Center"}]
Read the input and decode it into an array of events. Then, iterate through all the events and print each event's information in the following format:
Event: [name] on [date] at [location]
Print each event on a separate line, in the order they appear in the input array.
Input format: A JSON string representing an array of event associative arrays with keys name, date, and location
Expected output: Each event printed on a separate line in the format: Event: [name] on [date] at [location]
Try it yourself
<?php
// Read the JSON input
$input = fgets(STDIN);
// Decode the JSON string into an array
$events = (array)json_decode($input, true);
// TODO: Write your code below to iterate through events and print each one
?>All lessons in Logic & Flow
1Advanced Functions
Anonymous FunctionsClosures and 'use'Arrow FunctionsCallback FunctionsUsing 'call_user_func'Variable FunctionsPassing by ReferenceRecursive FunctionsRecap: Function Medley4Multi-dimensional Arrays
Creating a 2D ArrayAccessing 2D Array ElementsModifying 2D Array ElementsIterating with Nested Loops2D Associative ArraysRecap: Simple Grid Exercise2Advanced Array Manipulations
Adding with 'array_push'Removing with 'array_pop'Adding with 'array_unshift'Removing with 'array_shift'Merging Indexed ArraysMerging Associative ArraysExtracting with 'array_slice'Values with 'in_array'Keys with 'array_search'Recap: Playlist Exercise3Sorting Arrays
Sort Indexed Arrays AscendingSort Indexed Arrays DescendingSort Assoc Arrays by ValueSort Assoc Arrays by KeyNatural Order SortingCustom Sorting with 'usort'Recap: Leaderboard Sorting