Project Setup: Data Structure
Part of the Logic & Flow section of Coddy's PHP journey — lesson 33 of 68.
Challenge
EasyYou will receive one input: a JSON object representing a student gradebook. The gradebook uses student names as keys, and each student has an associative array containing their "id" (student ID number) and "grades" (an array of their test scores). Read the input, convert the JSON string to a 2D associative array, and print the entire gradebook structure using print_r().
This data structure will serve as the foundation for the gradebook system you'll build throughout this project.
Input format: One line containing a JSON object representing the gradebook (example: {"Alice":{"id":101,"grades":[85,92,78]},"Bob":{"id":102,"grades":[90,88,95]},"Charlie":{"id":103,"grades":[76,84,89]}})
Expected output: The gradebook array displayed using print_r()
Try it yourself
<?php
// Read the JSON input
$input = fgets(STDIN);
// TODO: Convert the JSON string to an associative array
// TODO: Print the gradebook structure using print_r()
?>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 Exercise5Student Gradebook
Project Setup: Data StructureAdding a New StudentAdding a Grade to a StudentCalculating Student's AverageFinding the Top StudentGenerating a Report Card3Sorting Arrays
Sort Indexed Arrays AscendingSort Indexed Arrays DescendingSort Assoc Arrays by ValueSort Assoc Arrays by KeyNatural Order SortingCustom Sorting with 'usort'Recap: Leaderboard Sorting