Skip to content

Commit 4abef5c

Browse files
018-Working with Foreach loops
1 parent a4ce2e4 commit 4abef5c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

018-working-with-foreach-loops.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
$fruits = ["apple", "banana", "orange"];
3+
foreach ($fruits as $fruit) {
4+
echo $fruit . "\n";
5+
}
6+
echo "\n";
7+
8+
$myArray = [
9+
"fruits" => ["apple", "banana", "orange"],
10+
"vegetables" => ["carrot", "potato", "onion"],
11+
"meat" => ["beef", "pork", "chicken"],
12+
"dairy" => ["milk", "yogurt", "cheese"],
13+
"drinks" => ["water", "tea", "coffee"],
14+
"food" => ["pizza", "burger", "salad"],
15+
"sports" => ["tennis", "soccer", "basketball"]
16+
];
17+
foreach ($myArray as $key => $value) {
18+
echo $key . " => ";
19+
foreach ($value as $item) {
20+
echo $item . ", ";
21+
}
22+
echo "\n";
23+
}

0 commit comments

Comments
 (0)