-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path6-loops.php
53 lines (43 loc) · 861 Bytes
/
6-loops.php
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
50
51
52
53
<?php
/**
* Loops
* https://www.php.net/manual/en/language.control-structures.php
* 1. ***While***
* 2. Do While
* 3. ***Foreach***
* 4. For
* 5. Continue and break
*/
echo '<pre>';
$x = 1;
// While (evaluates first).
while($x <= 5) {
echo "I have $x peanut butter cups!<br>";
$x++;
}
// Do while, executes at least once.
$y = 6;
do {
echo "Now I have $y peanut butter cups!! <br>";
$y++;
} while ($y <= 5);
// Foreach
$something = array(
'old' => 'pyramids',
'new' => 'keepin up...',
'borrowed' => 'can I have that back?',
'blue' => 'tobias fünke',
);
// Associative arrays
foreach ( $something as $key => $value ) {
echo "Something $key... ";
}
echo '<br>';
// Indexed arrays
foreach ( $something as $item ) {
var_dump( $item );
}
// For
for ( $i = 0; $i <= 10; $i++ ) {
echo "The number is: $i <br>";
}