Excellence | Service | Leadership and Good Governance | Innovation | Social Responsibility | Integrity | Professionalism | Spirituality
PHP arrays, looping statements
1. PHP Arrays
An array in PHP is a data structure that stores multiple values in a single variable.
Arrays allow developers to manage lists of data efficiently. PHP supports three types of
arrays:
• Indexed Arrays – Arrays with numeric keys.
• Associative Arrays – Arrays with named keys.
• Multidimensional Arrays – Arrays containing other arrays.
2. Looping Statements in PHP
Looping statements are used to execute a block of code multiple times. PHP
provides several types of loops:
a. For Loop
Used when the number of iterations is known.
b. While Loop
Used when the number of iterations is unknown but depends on a condition.
Excellence | Service | Leadership and Good Governance | Innovation | Social Responsibility | Integrity | Professionalism | Spirituality
c. Do-While Loop
Executes at least once before checking the condition.
d. Foreach Loop
Used specifically for iterating over arrays.
3. Using Looping Statements with Arrays
Loops are essential for handling arrays, especially when dealing with dynamic data.
Here’s how loops work with arrays:
a. Using for Loop with Indexed Arrays
b. Using foreach with Indexed and Associative Arrays
Excellence | Service | Leadership and Good Governance | Innovation | Social Responsibility | Integrity | Professionalism | Spirituality
c. Looping Through Multidimensional Arrays