PHP -Array -Schleife
for ($i = 0; $i < count($array); $i++) {
echo $array[$i]['filename'];
echo $array[$i]['filepath'];
}
Clever Cardinal
for ($i = 0; $i < count($array); $i++) {
echo $array[$i]['filename'];
echo $array[$i]['filepath'];
}
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
$arr = array(
'key1' => 'val1',
'key2' => 'val2',
'key3' => 'val3'
);
foreach ($arr as $key => $val) {
echo "$key => $val" . PHP_EOL;
}
<?php
$arr = ['Item 1', 'Item 2', 'Item 3'];
foreach ($arr as $item) {
var_dump($item);
}
$dict = array("key1"=>"35", "key2"=>"37", "key3"=>"43");
foreach($dict as $key => $val) {
echo "$key = $val<br>";
}
?>
$CodeWallTutorialArray = ["Eggs", "Bacon", "HashBrowns", "Beans", "Bread", "RedSauce"];
for ($i = 0; $i < count($CodeWallTutorialArray); $i++) {
echo $CodeWallTutorialArray[$i] ."<br />";
}Copy
$arr = array(
'key1' => 'val',
'key2' => 'another',
'another' => 'more stuff'
);
foreach ($arr as $key => $val){
//do stuff
}
//or alt syntax
foreach ($arr as $key => $val) :
//do stuff here as well
endforeach;