Reading and storing a list as an array PHP

PHPServer Side ProgrammingProgramming

For this, you can simply use for loop.

Example

The PHP code is as follows

 Live Demo

<!DOCTYPE html>
<html>
<body>
<?php
$list="10 20 30 40 50 60";
$arr=[];
$counter=0;
for($i=0;$i<count($list);$i++){
   if($list!==" "){
      $arr[$counter++]=$list;
   }
}
foreach($arr as $t){
   echo $t,"<br>";
}
?>
</body>
</html>

Output

This will produce the following output

10 20 30 40 50 60
raja
Published on 13-Oct-2020 07:09:14
Advertisements