NOTE: This invite-only release of SunSed Alpha is for testing purposes and in no way represents the final quality of the product — join the waitlist (~wait time: 2 weeks). SunSed release date is on March 11, 2022.

FOREACH

With a simple syntax, it iterates through each key/value of arrays, making it one of the easiest ways to loop through arrays. FOREACH has two valid syntaxes;

Value

On each loop, the value of the current element of the array will be assigned to the $value variable.

FOREACH($array AS $value) {
    // code to execute for each iteration
}

Key/Value

In addition to the first syntax, for each iteration, the key of the current element of the array will be assigned to the $key variable

FOREACH($array AS $key => $value) {
    // code to execute for each iteration
}

Example;

$purchases = [
    "02-02-2022" => "$299.99",
    "02-22-2022" => "$59.99",
]
FOREACH ($purchases AS $date => $price) {
    PRINT "Purchase of " . $price . " on " . $date
}
Copyright © SunSed LLC 2013-2021 All rights reserved.