Simple Machines Community Forum

General Community => Scripting Help => Topic started by: Kender on March 02, 2008, 04:03:45 AM

Title: create array with predefined $values
Post by: Kender on March 02, 2008, 04:03:45 AM
okay, here it is, simple

$arrvalue = "1,2,3,4,5";
$array = array($arrvalue);
print_r($array);

outputsArray (
  [0] => 1,2,3,4,5
)
How do i make it treat each seperate value as a new array item (seperated by comma)Array (
  [0] => 1,
  [1] => 2,
  [2] => 3,
  [3] => 4,
  [4] => 5
)
Title: Re: create array with predefined $values
Post by: Joshua Dickerson on March 02, 2008, 04:28:10 AM
Put in to geek speak: you have a comma delimited list that you want split up by the commas in to an array. explode()
Title: Re: create array with predefined $values
Post by: Kender on March 02, 2008, 04:37:32 AM
if i explode at the , wont it just give me...

Array (
  [0] = > 1 2 3 4 5
)


without the comma ?

i guess im asking for a more defined help... ie, where do i put the explode statement, etc
Title: Re: create array with predefined $values
Post by: Joshua Dickerson on March 02, 2008, 04:48:17 AM
www.php.net/explode read
Title: Re: create array with predefined $values
Post by: Kender on March 02, 2008, 05:22:48 AM
*eats crow*

thanks for pointing that out.. I have used explode many times to create an array and never thought of using it in this instance