shakeelstha Posted March 9, 2008 Share Posted March 9, 2008 I have a php array. I need to pass it to the javascript function as parameter. Within the javascript function it should work as javascript array not php array..How can I do that? Link to comment https://forums.phpfreaks.com/topic/95184-pass-php-array-into-javascript-function-as-parameter/ Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 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>"; Link to comment https://forums.phpfreaks.com/topic/95184-pass-php-array-into-javascript-function-as-parameter/#findComment-487574 Share on other sites More sharing options...
shakeelstha Posted March 10, 2008 Author Share Posted March 10, 2008 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. Link to comment https://forums.phpfreaks.com/topic/95184-pass-php-array-into-javascript-function-as-parameter/#findComment-488252 Share on other sites More sharing options...
Xajel Posted March 10, 2008 Share Posted March 10, 2008 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 Link to comment https://forums.phpfreaks.com/topic/95184-pass-php-array-into-javascript-function-as-parameter/#findComment-488289 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.