Php - foreach

About

foreach is a loop structure over an array

For each

See also: PHP - For loop

Example

$colors = array('red', 'blue', 'green', 'yellow');

foreach ($colors as $color) {
    echo "Do you like $color?\n";
}


// Changing element in the loop
foreach ($colors as $key => $color) {
    $colors[$key] = strtoupper($color);
}

Powered by ComboStrap