assigning multidimensional php array to javascript array

前端 未结 5 1579
梦如初夏
梦如初夏 2021-01-17 02:29

I know this may be a duplicate, but I cant wrap my brain around the other examples. Help would be appreciated. I have a php array that i need to assign to a javascript array

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-17 03:02

    1. You can't use numbers as variable names in javascript.
    2. You don't need to use "var" with each line. Something like

      var test = [];
      test[1] = 'some value';
      test[2] = 'some value';
      
    3. You probably want to look at using the JSON_ENCODE function from PHP

提交回复
热议问题