CONVERTING PHP MULTI-DIMENSIONAL ARRAY TO JAVASCRIPT ARRAY – USING JSON ENCODING
Easy to impliment……:)

RJ Solusoft

As you know PHP is a Server-side Scripting language. It executes only at the time of page loading and reaches response to the browser as HTML. So PHP multidimensional array cannot assign to JavaScript array directly, since JavaScript is a Client-side Scripting language. That means it runs inside the browser.

So when you need to use multi-dimensional array (from database or elsewhere) as JavaScript array, a better way to do this is the use of JSON array, which is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language.

First convert the PHP array to JSON array using json_encode function in PHP.

For example,


$json_array=json_encode($data);   // $ data is a multidimensional PHP array.

Now $json_array is…

View original post 57 more words

Advertisements