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? Quote 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 Quote 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? Quote 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() Quote 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... Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.