Menu
Coddy logo textTech

Event Data

Part of the Logic & Flow section of Coddy's PHP journey — lesson 59 of 68.

challenge icon

Challenge

Easy

You 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