Jump to content

pass php array into javascript function as parameter


shakeelstha

Recommended Posts

you have to echo the array using normal JS array making

 

example

 

$myarray = array("value1", "value2", "value3", etc..);

echo "<script language=\"javascript\">";
echo "var jarray = array();";
for ($i=0; $i<count($myarray); $i++) {
echo "jarray[$i] = '$myarray[$i]';\n;
}
echo "</script>";

This is not what I am looking for. I need to pass the whole php array into javascript function as parameter. Not just converting php array into javascript array......................the actual parameter should be in php array and the referenced parameter should be in javascipt array.

 

 

well, other than what I said before, this is not possible

 

PHP is server-side script, so only the server will handle it's enviroment

 

javascript is client-side script, and only the client will handle it's enviroment

 

the server is not able to handle the javascript, and the client is not able to handle PHP script,

 

so you're limited to echo the array like the above example

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.