Best way to create an empty object in JSON with PHP?

前端 未结 7 1734
情深已故
情深已故 2020-11-27 03:26

To create an empty JSON object I do usually use:

json_encode((object) null);

casting null to an object works, but is there any other prefer

相关标签:
7条回答
  • 2020-11-27 04:30

    json_encode($array, JSON_FORCE_OBJECT) will do it too. see https://www.php.net/manual/en/function.json-encode.php

    0 讨论(0)
提交回复
热议问题