In PHP, there are several ways to loop through an indexed (numerically indexed) array. Here are some common methods:
<?php
$indexedArray = array(1, 2, 3, 4, 5);
$arrayLength = count($indexedArray);
for ($i = 0; $i < $arrayLength; $i++) {
echo "Index: $i, Value: " . $indexedArray[$i] . "<br>";
}
?>
<?php
$indexedArray = array(1, 2, 3, 4, 5);
foreach ($indexedArray as $index => $value) {
echo "Index: $index, Value: $value<br>";
}
?>
Note: Using a foreach loop is often preferred for iterating through arrays in PHP, especially when dealing with indexed arrays, as it simplifies the syntax and eliminates the need for managing indices manually.