Syntax error How to display array values with do while or for statement in my PHP?

How to display array values with do while or for statement in my PHP?



Following is the syntax to display array values

do{
   //statement1
   //statement2
   .
   .
   .
   n
}
while(yourCondition);

The PHP code is as follows −

Example

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
   $values=array('John','David','Mike','Sam','Carol');
   $i=0;
   $len=count($values);
   do{
      echo $values[$i]," ";
      $i++;
   }
   while($i<$len)
?>
</body>
</html>

Output

John David Mike Sam Carol
Updated on: 2020-11-20T05:32:52+05:30

244 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements