force json_encode to create strings

后端 未结 4 1826
感动是毒
感动是毒 2020-12-21 14:51

I have to json_encode a PHP array to a JavaScript array. Unfortunately the jQuery library I am using will not properly process that array if it contains ints instead of stri

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-21 15:26

    Define them in your array as strings, or if it is coming from somewhere else:

    $data = json_encode(array_map('strval', $data));
    

提交回复
热议问题