Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP array printing using a loop

Tags:

arrays

loops

php

If I know the length of an array, how do I print each of its values in a loop?

like image 307
user156073 Avatar asked Aug 18 '09 13:08

user156073


People also ask

Can we use for loop for array in PHP?

The foreach loop works only on arrays, and is used to loop through each key/value pair in an array.


1 Answers

$array = array("Jonathan","Sampson");  foreach($array as $value) {   print $value; } 

or

$length = count($array); for ($i = 0; $i < $length; $i++) {   print $array[$i]; } 
like image 158
Sampson Avatar answered Oct 07 '22 18:10

Sampson