Concept
How does PHP use foreach loops to iterate over array elements?
ComputerScienceOne / Foreach Loops
"Finally, PHP supports foreach loops using the keyword foreach. Some of this will be a preview of Section 42 where we discuss arrays in PHP. In short you can iterate over the elements of an array as follows.\n\n$arr = array(1.41, 2.71, 3.14);\n\nforeach($arr as $x) {\n\n//x now holds the \"current\" element in arr\n\nActually, PHP supports associative arrays, which are not the same thing as traditional arrays."
Related Ideas
- How are foreach loops used to iterate over array elements in PHP?ComputerScienceOne · Do-While Loops
- How does the foreach syntax iterate over an array in PHP?ComputerScienceOne · Normalizing a Number
- How can you iterate over indexed and associative arrays in PHP?ComputerScienceOne · Iteration
- How can you iterate through an array using foreach?ComputerScienceOne · Adding Elements
- Can PHP array indices be non-contiguous?ComputerScienceOne · Strings as Indices
- How do you create and index arrays in PHP?ComputerScienceOne · Creating Arrays
- How are for loops structured in PHP?ComputerScienceOne · For Loops
- How can you simulate a foreach loop when iterating over an array in C?ComputerScienceOne · Other Issues