Possible Duplicate:
Php pass array to Javascript
How to pass PHP array parameter to Javascript Function?
So I'm trying to pull an individual element at random from an array consisting of data pulled from a database. This is a simplified version of the php code.
function getID() {
$result = array('1','2','3','4');
$id = $result[array_rand($result)];
return $id;
}
From here, I'm defining a JavaScript variable using the returned ID.
Here's the weird thing, when I define the JS variable using the passed return $id, the javascript variable is defined as = "Array" instead of the $id data.
IF I change the php code to this:
function getID() {
$result = array('1','2','3','4');
$id = array_rand($result);
return $id;
}
The javascript variable is defined as the $id, which is the array key, not the array data.
So I tried changing the php code to this:
function getID() {
$result = array('1','2','3','4');
return $result[0];
}
But the javascript gets defined as "Array" again.
It's as if the php won't take an array marker.
Any ideas here are welcome.