Reading and storing a list as an array PHP


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

Updated on: 13-Oct-2020

127 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements