xxxxxxxxxx
$letters = ['a','b','c'];
foreach ($letters as $item) {
echo $item;
}
xxxxxxxxxx
$clothes = array("hat","shoe","shirt");
foreach ($clothes as $item) {
echo $item;
}
xxxxxxxxxx
for ($i = 0; $i < count($array); $i++) {
echo $array[$i]['filename'];
echo $array[$i]['filepath'];
}
xxxxxxxxxx
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
xxxxxxxxxx
foreach($array as $item) {
echo $item['filename'];
echo $item['filepath'];
// To know what's in $item
echo '<pre>'; var_dump($item);
}
xxxxxxxxxx
foreach($array as $i => $item) {
echo $item[$i]['filename'];
echo $item[$i]['filepath'];
// $array[$i] is same as $item
}
xxxxxxxxxx
foreach($array as $i => $item) {
echo $array[$i]['filename'];
echo $array[$i]['filepath'];
// $array[$i] is same as $item
}
xxxxxxxxxx
$CodeWallTutorialArray = ["Eggs", "Bacon", "HashBrowns", "Beans", "Bread", "RedSauce"];
for ($i = 0; $i < count($CodeWallTutorialArray); $i++) {
echo $CodeWallTutorialArray[$i] ."<br />";
}Copy
xxxxxxxxxx
foreach($array as $item) {
echo $item['filename'];
echo $item['filepath'];
// to know what's in $item
echo '<pre>'; var_dump($item);
}
xxxxxxxxxx
foreach (array_expression as $value)
statement
foreach (array_expression as $key => $value)
statement