Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

simple listing problem

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

simple listing problem

Postby digitalbloke » Wed Jul 23, 2003 6:51 am

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
digitalbloke
New php-forum User
New php-forum User
 
Posts: 59
Joined: Tue Jul 01, 2003 7:02 am

Postby swirlee » Wed Jul 23, 2003 7:04 am

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: Select all
<?
   // 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";
   }
?>
User avatar
swirlee
Moderator
Moderator
 
Posts: 2272
Joined: Sat Jul 05, 2003 1:18 pm
Location: A bunk in the back

Postby digitalbloke » Thu Jul 24, 2003 5:38 am

spot on!

many thanks!
digitalbloke
New php-forum User
New php-forum User
 
Posts: 59
Joined: Tue Jul 01, 2003 7:02 am


Return to PHP coding => General

Who is online

Users browsing this forum: Google [Bot] and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.