Passing PHP JSON to [removed] echo json_encode vs echo json declaration

后端 未结 9 2267
猫巷女王i
猫巷女王i 2021-01-05 01:52

I\'m trying to create a common constants file to share between php and javascript, using JSON to store the constants. But I\'m wondering why pass the JSON from PHP to javasc

9条回答
  •  半阙折子戏
    2021-01-05 02:00

    Even though it may seem like overkill for your particular problem, I would go for the json_encode/parse option still. Why? you ask. Well, think of it as avoiding duplication. If you encode/parse you can keep the constants in an object easily readable by you PHP-code. And the same for your JS code.

    It simply eliminates the need to fiddle with it.

提交回复
热议问题