Panafrikan PHP

An educational initiative by EColSi

Discover EColSi
Choose your language
Explore the course

B02 — Data that tells a story: variables and types

Basic level · Lesson B02

B02 — Data that tells a story: variables and types

B02 — Data that tells a story: variables and types

Result: an educational resource sheet with coherent data.
Central concept: each data has meaning and type.
Guideline time: 60–90 minutes.

Is “5”, 5 and true the same thing?

No. Although they may look similar, they represent text, a number, and a logical state. Choosing the right type avoids strange calculations and hard-to-understand rules.

Previous connection

In B01 we use name, goal and hours. Now we will distinguish string, int, float, bool and null.

Concepts

  • string: text, such as a title.
  • int: integer, such as 12 sessions.
  • float: decimal, such as 1.5 hours.
  • bool: true or false.
  • null: intentional absence of a value.

Type is not decoration: it determines which operations make sense.

Guided laboratory

<?php
$title = "Introducción a PHP";
$sessions = 6;
$hoursPerSession = 1.5;
$available = true;
$certificateDate = null;

echo "Curso: $title<br>";
echo "Horas totales: " . ($sessions * $hoursPerSession) . "<br>";
echo $available ? "Disponible" : "Cerrado";

Use var_dump($sessions); during scanning to observe value and type; remove it from the final presentation.

Medium Mission

Create a file for a fictitious club or workshop with six variables and at least four types. Explain why a quantity should not be stored as text.

University Extension

Try strict comparisons between 5 and "5". Documents the output of == and ===, explains the risk of implicit conversions, and proposes consistent variable names.

Tests

  • Change availability between true and false.
  • Use zero sessions.
  • Check the types with var_dump.

Delivery

Send code, capture, variable-type-reason table and a question. SEND TO TUTOR.

Next: B03 — Calculate an achievable goal.

Comments

Popular posts from this blog

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

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