Files
web_2025/R3.01/tp/tp1/ex2/index.php
T

52 lines
848 B
PHP
Raw Normal View History

2026-03-23 14:01:45 +01:00
<?php
2026-04-02 13:48:28 +02:00
$clients = [
"Luc",
7 => "Paul",
2 =>"Martin",
"Arnaud"
2026-03-23 14:01:45 +01:00
];
2026-04-02 13:48:28 +02:00
var_dump($clients);
2026-03-23 14:01:45 +01:00
$produits = [
2026-04-02 13:48:28 +02:00
20 => "Chemise",
3 => "Pantalon",
10 => "Jupe",
"Veste",
"Blouson"
2026-03-23 14:01:45 +01:00
];
$array = ["a","b","c"];
$array[] = "d";
$array[10] = "j";
unset($array[2]);
echo "<pre>";
print_r($clients);
print_r($produits);
print_r($array);
echo "</pre>";
2026-04-02 13:48:28 +02:00
// Exercice 2.1
$tab = [];
$somme = 0;
for ($i = 0; $i < 10; $i++) {
$somme += $i; // somme des entiers de 0 à i
$tab[$i] = $somme; // la clé i contient cette somme
}
print_r($tab);
// Exercice 2.2
for ($debut = 1; $debut <= 50; $debut += 10) {
echo "<p>";
for ($i = $debut; $i < $debut + 10; $i++) {
if ($i % 2 === 0) {
echo "<strong>$i</strong> ";
} else {
echo "<em>$i</em> ";
}
}
echo "</p>";
}
2026-03-23 14:01:45 +01:00
?>