English
Tamil Nadu Board of Secondary EducationHSC Science Class 12

Explain working of loops in array.

Advertisements
Advertisements

Question

Explain working of loops in array.

Answer in Brief
Advertisements

Solution

Using Foreach loop:

  • The foreach statement is used to loop through arrays.
  • For each pass, the value of the current array element is assigned to $value and the array pointer is moved by one and in the next pass, the next element will be processed.

Example:

<?php
$Student_name = arrayO’Magilan”, “Iniyan”, “Nilani” “Sibi” “Shini”); foreach ($Student_name as $value) { echo “$value <br>”;
}
?>

Using For Loop:

To loop through and print all the values of an indexed array.

Example:

<?php$cars = arrayC’Volvo”, “BMW”, “Toyota”);
$arrlength = count(cars);
for($x = 0; $x < $arrlength; $x++){
echo $cars[$x];
echo “<br>”;
}
?>
shaalaa.com
Looping Structure
  Is there an error in this question or solution?
Chapter 7: Looping Structure - Evaluation - PART – IV [Page 118]

APPEARS IN

Samacheer Kalvi Computer Applications [English] Class 12 TN Board
Chapter 7 Looping Structure
Evaluation - PART – IV | Q 5. | Page 118
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×