I have an array in javascript that I need to join and send through a URL to PHP such as the following:
var objects = [];
objects.splice("red",0,"apple");
objects.splice("yellow",0,"banana");
objects.splice("purple",0,"grape");
var string = objects.join("+");
$("#print_div").load("fruits.php?fruits=" + string);
In PHP, I want to recieve the string and convert it back to an array… something like this:
$fruits = explode(" ", $_REQUEST['fruits']);
foreach($fruits as $key => $value){
echo "The " . $value . " is " . $key;
}
Maybe it is the join or the splice in javascript that wont make this work, or maybe the explode in php. Im not sure, but I need a solution to be able to create custom indexes to an array in javascript and then send to php and still be able to access the index and value names.
Thanks for your help!
Suppose this is your object:
Pass it to php like so: (ref)
Use it like so: