Forum Moderators: coopster

Message Too Old, No Replies

Trying to put variable inside an array

         

londrum

4:25 pm on Mar 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



hello. got a little head scratcher here...

i've got a variable with a load of numbers in it, seperated by commas.

eg.
$posts = "555,666,777,888,999";

and i am trying to put those numbers inside an array

eg.
array($posts)

but it only ever takes notice of the first number (555). but when i do it like this instead,
array(555,666,777,888,999)
then it works fine

i can't see how how swapping the numbers for the variable would make a difference?

when i do print_r on array($posts), i get this
array([0] => 1074,1139,1076,1494,1078)

when i really want it to say this
array(1074,1139,1076,1494,1078)

anyone know where i'm going wrong?

brotherhood of LAN

4:28 pm on Mar 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



$posts = "555,666,777,888,999";
$posts = explode(',',$posts);

explode [uk.php.net] will do the job of turning the string into an array

londrum

4:40 pm on Mar 24, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



genius. it worked, thanks