I have a PHP String like this:
$string = 'a => 1 , b => 2 , c => 3 , d => 4';
which I have built from data from a database, where each "x => y" represents an associative relationship between x and y.
I am then transferring this string to the html document (JQuery) and attempting to make an array out of it in JavaScript, so that I may process on the client side.
QUESTION:
Is it possible to create a JavaScript Array out of a string?
For example I need to be able to retrieve the values in the array by calling 'alert(array["c"]);' or something similar.
NOTE – feel free to alter the semantics of the above string ($string) as necessary.
Any help appreciated guys….
PHP Code
(for instance, a file, like array.php):
jQuery code:
You can use this for arrays, remember the
'json'tag at the end of the request everytime.