Concept

How can you iterate through an array using foreach?

ComputerScienceOne / Adding Elements

"For each key value pair:\n\nforeach($arr as $key => $val) {\n\nprint \"$key maps to $val\n\n\";\n\n}\n\nThis syntax gives you access to both the key and the value for each element in the array $arr. The keyword as is used to denote the variable names $key and $val that will be changed on each iteration of the loop. You need not use the identifiers $key and $val; you can use any legal variable names for the key/value variables. If you do not need the keys when iterating, you can use the following shorthand syntax.\n\nFor each value:\n\nforeach($arr as $val) {\n\nprint \"$val\n\n\";\n\n}"

Related Ideas

How can you iterate through an array using foreach? | ComputerScienceOne | Bifalgorithm | Bifalgorithm