Page 1 of 1

Splitting up a value

Posted: Tue Feb 21, 2006 3:19 pm
by VKX
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!

Posted: Tue Feb 21, 2006 3:21 pm
by feyd

Posted: Tue Feb 21, 2006 3:28 pm
by VKX
Great! So my code now looks like this:

Code: Select all

<?php
		$p_show = explode(",", $p_tbmshows);
			echo $p_show[0]; echo "<br>";
			echo $p_show[1]; echo "<br>";
		?>
How could I loop is so that it echo's as many times as there are rows in the array?

Posted: Tue Feb 21, 2006 3:32 pm
by feyd
With a loop. It could be suggested that you need to read the manual a bit more...

while, for, foreach

Posted: Tue Feb 21, 2006 3:33 pm
by RobertGonzalez
Use a for loop or a foreach loop...

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";
}
?>
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).

Posted: Tue Feb 21, 2006 3:42 pm
by VKX
feyd wrote:With a loop. It could be suggested that you need to read the manual a bit more...

while, for, foreach
Of course I gave that a shot, but it's giving me an infinite loop. I don't know array stuff very well, as I'm self taught and still learning. I figured I had to do something special for the array . . .

Posted: Tue Feb 21, 2006 3:49 pm
by VKX
Just syntax errors. It's nested in a bunch of code.

Thanks again!