ForEach Loop
Home Courses Community Support
ForEach Loop

foreach loop is used for array and objects. Syntax of foreach loop is as below-

foreach (array_expression as $value)


At each iterance the value of current element is assigned to the $value and internal array pointer is increased by one.

See below example -

$arr = array(1,2,3,4,5);
foreach ($arr as $value) {
    $value = $value * 2;
// $arr is now array(2, 4, 6, 8, 10)


In the above code, the array values was 1,2,3,4,5 and we set them to 2,4,6,8,10.



← Preview

For Loop

Next →

User Defined Function


Our mission is to provide highly effective and quality education via innovative solutions. Geeksdemy look forward to bridge the gap between in-demand technology and academics in order to deliver innovative, easy, interesting and affordable learning across the Globe.


  • Python
  • Game Development with Unity 3D
  • Arduino
  • PCB & Circuit Designing
  • Robotics and Embedded C
  • 8051/8052 Embedded Systems
  • QuadCopter & UAV
  • MATLAB with Robotics
  • Raspberry Pi
Learn On the Go!
Get the Android App
Get the iOS App