convert php associative array into javascript object

后端 未结 5 1096
花落未央
花落未央 2020-12-28 15:52

I\'m trying to load Chinese words as keys, and their English translations as values from a database into a php array so then I can use them on the client side in JavaScript.

5条回答
  •  -上瘾入骨i
    2020-12-28 16:03

    For me the simplest way to convert php array to javascript object is to json_encode the php array then JSON.parse it from javascript like this:

     "one", 2 => "two", 3 => "three"];
    ?>
    
    
    

提交回复
热议问题