javascript - Associative array to String and String to associative array -
i have convert an associative array string
in php
. doing as
$cookievalue = http_build_query(arr,'','sep');
and setting cookie using setcookie
.
setcookie('subs',$cookievalue,0,'/');
cookie in js side looks like
"emailid=a1%40a.comsepmaths=0sepphysics=1sepchemistry=2sepbotany=3sepzoology=4se ptamil=5sepenglish=6seppolity=7sepgk=8sephistory=9"
i trying convert associative array.
i tried json.parse
. it's not useful in case.
i free change both php side , js side functions
. aim should easy convert forth , back.
i tried implode
on php also.
try this:
var = "emailid=a1%40a.comsepmaths=0sepphysics=1sepchemistry=2sepbotany=3sepzoology=4septamil=5sepenglish=6seppolity=7sepgk=8sephistory=9"; var myarr = {}; var sep = "sep"; a.split(sep).foreach(function(item){ var sepp = item.indexof("="); myarr[item.substr(0,sepp)] = decodeuricomponent(item.substr(sepp+1)); }); console.log(myarr);
here's demo.
Comments
Post a Comment