I have a value, $shows, that contains a list of dates like this:
2005-01-20,2005-03-05,2006-04-01
There are an undeterminded number of values in $shows. How can I split them up and up them in variables? IE,
$date1 = 2005-01-20
$date2 = 2005-03-05
$date3 = 2006-04-01
Thanks in advance guys!
Splitting up a value
Moderator: General Moderators
Great! So my code now looks like this:
How could I loop is so that it echo's as many times as there are rows in the array?
Code: Select all
<?php
$p_show = explode(",", $p_tbmshows);
echo $p_show[0]; echo "<br>";
echo $p_show[1]; echo "<br>";
?>- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Use a for loop or a foreach loop...
EDIT: Dang, Feyd the speedtastic beat me to it. I thought I was typing fast, too. Oh well, just goes to show that Feyd can literally post 3000 different replies in like four seconds. (And he knows what he talking about, too).
Code: Select all
<?php
$p_show = explode(",", $p_tbmshows);
foreach ($p_show as $show_this)
{
echo $show_this . "<br />\n";
}
// Or alternatively
for ($i = 0; $i < count($p_show); $i++)
{
echo $p_show[$i] . "<br />\n";
}
?>