galvin Posted January 14, 2011 Share Posted January 14, 2011 What is best way to take a PHP array (say it's called $_SESSION['list']) and turn it into a Javascript array? Link to comment https://forums.phpfreaks.com/topic/224387-turn-php-array-into-javascript-array/ Share on other sites More sharing options...
vijdev Posted January 14, 2011 Share Posted January 14, 2011 use JSON Link to comment https://forums.phpfreaks.com/topic/224387-turn-php-array-into-javascript-array/#findComment-1159199 Share on other sites More sharing options...
haku Posted January 14, 2011 Share Posted January 14, 2011 Depends on how you are passing it to your javascript. Are you printing it to the page, or are you sending it through an AJAX call? Link to comment https://forums.phpfreaks.com/topic/224387-turn-php-array-into-javascript-array/#findComment-1159226 Share on other sites More sharing options...
salathe Posted January 14, 2011 Share Posted January 14, 2011 json_encode() Link to comment https://forums.phpfreaks.com/topic/224387-turn-php-array-into-javascript-array/#findComment-1159281 Share on other sites More sharing options...
galvin Posted January 14, 2011 Author Share Posted January 14, 2011 haku, I would be sending it through an AJAX call... Link to comment https://forums.phpfreaks.com/topic/224387-turn-php-array-into-javascript-array/#findComment-1159369 Share on other sites More sharing options...
haku Posted January 14, 2011 Share Posted January 14, 2011 In that case, the advice given by the other guys in this thread is the way you should do it. Link to comment https://forums.phpfreaks.com/topic/224387-turn-php-array-into-javascript-array/#findComment-1159388 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.