3

I have array came from my ajax

$contestant_name_arr = $_GET['contestant_name_arr'];
print_r($contestant_name_arr);

Whenever i try to get the value of each in loop i got error because instead of this

Array ( [0] => value1,value2 )

It should be look like this:

Array ( 
    [0] => value1 
    [1] => value2
)

How do I separate like that in the example above.

Kevin
  • 41,694
  • 12
  • 53
  • 70
  • Possible duplicate of [PHP: Convert comma separated value pair string to Array](http://stackoverflow.com/questions/34830374/php-convert-comma-separated-value-pair-string-to-array) – LF00 Aug 29 '16 at 00:38

1 Answers1

8

Either devise your url query string to be:

http://yourhost.com?contestant_name_arr[0]=value&contestant_name_arr[1]=value2

Or just simply explode;

$contestant_name_arr = explode(',', $contestant_name_arr[0]);
Kevin
  • 41,694
  • 12
  • 53
  • 70
  • You can also leave out the numbers and do this: `http://yourhost.com?contestant_name_arr[]=value&contestant_name_arr[]=value2`. PHP will automatically number them. – Moshe Katz Aug 29 '16 at 12:04