simple listing problem

A

Anonymous

Guest
Hi i am very new to PHP and learning all the time. could someone please tell me how to take the values seperated by commers (,) and list them.

ie.

$values = "1,2,3,4"

to list as

1
2
3
4

i know there could be some sort of loop and some html but im not sure about the php


Many thanks


Digitalbloke
 
Do you know how to use arrays, digitalbloke? If you have a delimited list, you can use explode() to place each delimited item into an element of an array. So, if they're separated by commas, you could do the following:

Code:
<?
   // the values
   $values = '1,2,3,4';

   /* explode() them into an array named $value_array
      the first argument is the delimiter, in this case ','
   */
   $value_array = explode(',', $values);

   /* now use foreach(), which will loop through the array and 
      output each value
   */
   foreach($value_array as $value) {
      echo $value . "<br>\n";
   }
?>
 
Back
Top