Panafrikan PHP

An educational initiative by EColSi

Discover EColSi
Choose your language
Explore the course

B07 | Organize a catalog with PHP arrays

Basic level · Lesson B07

B07 | Organize a catalog with PHP arrays

B07 | Organize a catalog with PHP arrays

Result: resource catalog filtered by level.
Core concept: A collection represents several related records.
Guideline time: 90–120 minutes.

How do you save ten resources without creating thirty variables?

With arrays. An indexed array represents a list; an associative one represents a record with meaningful keys.

Previous connection

We will apply the functions of B06 while traversing collections as in B05.

Guided laboratory

<?php
$resources = [
    ["title" => "Variables", "level" => "basic", "minutes" => 25],
    ["title" => "APIs", "level" => "advanced", "minutes" => 45],
    ["title" => "Functions", "level" => "basic", "minutes" => 35],
];

$selectedLevel = "basic";
foreach ($resources as $resource) {
    if ($resource["level"] !== $selectedLevel) {
        continue;
    }
    echo "<p>{$resource['title']} — {$resource['minutes']} min</p>";
}

Medium Mission

Create five resources with title, level and duration. Filters by level and displays a message if there are no results.

University Extension

Extract the filter to a function, keep the original collection, and analyze what would happen if a key is missing. Implements minimal validation of the structure.

Tests

Level with several results, one, none and an incomplete record.

Delivery

Submit code, explained structure, results and a proposed improvement. SEND TO TUTOR.

Next: B08 — Forms.

Comments

Popular posts from this blog

Bem-vindo ao Panafrikan PHP: aprenda, construa e compartilhe

Bienvenue sur Panafrikan PHP : apprenez, créez et partagez