Click to See Complete Forum and Search --> : Populate array from url or form


BluesMan
11-26-2005, 09:11 AM
I want to populate an array from either the url or a form. Something like this:

user enters url: index.php?numbers=1,2,3,4,5,6

In index.php I have
$numbers = $_GET['numbers'];
$test = array($numbers);

I want that to become
$test = array(1,2,3,4,5,6);

My code doesn't work - $numbers is an 11 charakter string.
$numbers becomes $numbers = "1,2,3,4,5,6"

Is there any (preferrably simple) way to do this?

What I want in the end, is to get the numbers into an array and compare them with another array. I've got that part of the code working, but can't populate the $numbers properly.

It doesn't matter whether the values are integers or strings, as long as I get 6 of them and not only one as I do now.

Scleppel
11-26-2005, 09:17 AM
You want to use the explode (http://php.net/explode) function:
$your_array = explode(',',$_GET['numbers']);

# test output
print_r($your_array);

BluesMan
11-26-2005, 11:30 AM
That was exactly what I wanted. A little tweaking, and I'll have what I want.

Thanks a heap!

:) :D :cool: