If I know the length of an array, how do I print each of its values in a loop?
The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.
$array = array("Jonathan","Sampson"); foreach($array as $value) { print $value; }
or
$length = count($array); for ($i = 0; $i < $length; $i++) { print $array[$i]; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With