-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path07_loops.php
More file actions
49 lines (42 loc) · 900 Bytes
/
Copy path07_loops.php
File metadata and controls
49 lines (42 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<?php
//Les boucles
// boucle sans compteur - while
while (true) { // boucle infinie: A NE PAS EXECUTER
// faire quelque chose continuellement
}
// boucle avec compteur $counter
$counter = 0;
while ($counter < 10) {
echo $counter.'<br>';
// if ($counter > 5) break;
$counter++;
}
// do - while
$counter = 0;
do {
// Do some code right here
$counter++;
} while ($counter < 10);
// for
for ($i = 0; $i < 10; $i++) {
echo $i."<br>";
}
//if continue
// foreach
$fruits = ["Banane", "Pomme", "Orange"];
foreach ($fruits as $i => $fruit) {
echo $i . ' ' . $fruit . '<br>';
}
// Boucle et tableaux associatifs.
$person = [
'nom' => 'Chihed',
'prenom' => 'Aicha',
'age' => 30,
'hobbies' => ['Tennis', 'Jeux video'],
];
foreach ($person as $key => $value) {
if ($key === 'hobbies') {
break;
}
echo $key . ' ' . $value . '<br>';
}