Skip links

PHP array convert to Java Script array

Sometimes when we using php, we want to convert php array to java script array.php array can be convert to java script easily.Here is a easy and best methods to do this.
PHP provides json_encode() function to convert PHP arrays into Java Script code.

$php_array = array('id','username','email');

This can be convert to java script as follows.


 id [1] => username [2] => email )
$js_array = json_encode($php_array);
/* Apply json_encode()