PDA

View Full Version : Can you give arrays to PHP?


phloam
11-22-2006, 01:07 PM
This doesn't seem to be working...

e.g. :

var lv = new LoadVars();
lv.Something = "sdfsdf";
lv.BitsINeed = ["dog","cat","bear","fridge","crap"];

lv.sendAndLoad("posting.php", lv, "a");


anything I'm doing wrong here? When I echo that array (from inside a loop) in PHP (just as a test) it does not give me the values back...


$myArray = $_POST['BitsINeed'];
for ($i=0; $i<count($myArray); $i++)
{
echo "myArray[i] = " . $myArray[i];
}


Thanks if any can help,
a.p.

Cota
11-22-2006, 01:17 PM
The easiest way, in my opinion, would be to set up the flash array into one long string seperated by comma's. Then in php, like you would Flash, split the string by the comma, using split() or explode() in php.

CyanBlue
11-22-2006, 01:55 PM
If you really want to pass any object(which includes array) from Flash to PHP, you will need to use Flash Remoting(or AMFPHP) to achieve that... Otherwise, what Cota suggested is the only other option available...

jsebrech
11-22-2006, 07:11 PM
For passing around data objects, json is a pretty good solution. Ready-made encoding/parsing of all the common primitives between different programming environments.

http://json.org/

That site has code for actionscript and for php. I use it for all my client/server communications of data objects in web apps now.

phloam
11-23-2006, 11:07 PM
thanks all..
I forgot about splitting a string in PHP. That'll do for now...

I want to look into Flash remoting one day, but I don't think I have time for this project.

Had a quick look at http://json.org/ - looks interesting, but I think for this project I'll stick to the quick and nasty fix.

Cheers,
a.p.

CyanBlue
11-24-2006, 12:59 AM
Just out of curiosity, how weel JSON work with/on different browsers???

jsebrech
11-24-2006, 08:01 AM
JSON objects use the most basic of the javascript syntax, so at the very least you should be able to eval them in any javascript engine. The JSON libraries for javascript tend to have additional checks so you don't accidentally execute code embedded in the JSON object, and provide methods for encoding. But the nice thing is that you can easily construct JSON objects using string concatenation. They're very simple to generate and parse.

I've just built a web grid control using JSON objects for data transfer, and I must say I had a good experience. I'll be using them a lot from now on.

CyanBlue
11-24-2006, 01:45 PM
Thanks for the information... I sure will take a look... ;)