convert php associative array into javascript object

后端 未结 5 1129
花落未央
花落未央 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条回答
  •  感动是毒
    2020-12-28 16:18

    You can use json_encode() to make array as an json object like,

    var words = ;// don't use quotes
    $.each(words, function(key, value) {
        console.log('stuff : ' + key + ", " + value);
    });
    

提交回复
热议问题