{"id":134984,"date":"2020-07-09T05:51:51","date_gmt":"2020-07-08T21:51:51","guid":{"rendered":"http:\/\/4563.org\/?p=134984"},"modified":"2020-07-09T05:51:51","modified_gmt":"2020-07-08T21:51:51","slug":"php-%e9%87%8c-emptyobject%e6%98%af-false-%e8%bf%98%e6%98%af-true","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=134984","title":{"rendered":"PHP \u91cc empty((object)[])\u662f false \u8fd8\u662f true?"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  PHP \u91cc empty((object)[])\u662f false \u8fd8\u662f true?               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <span><i><\/i> 18<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\">                        \u8fd9\u4e48\u8bbe\u8ba1\u662f\u5426\u7b26\u5408\u76f4\u89c9?      <\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>32<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"2406757\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ksaa0096329 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             false<br \/>\u6709\u65f6\u95f4\u6765\u95ee,\u65e9\u5c31\u6d4b\u8bd5\u51fa\u6765\u4e86.<br \/>\u518d\u8bf4\u4e86 \u4f60\u8fd9\u79cd\u5199\u6cd5\u6709\u4ec0\u4e48\u610f\u4e49.                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406758\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : iamverylovely <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u7b26\u5408\u554a\uff0c\u4e0d\u7136\u53c8\u8981 emptyObject();                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406759\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : zarte <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             false \u4e00\u5b9a\u662f\u7528\u4e86\u90a3\u4e9b\u67e5\u8be2\u56de\u6765\u662f obj \u7684 orm \u4e86\u5427\uff0c\u54c8\u54c8\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406760\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovecy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             empty\uff0c\u53ea\u9488\u5bf9<br \/>0\uff0c\u7a7a string\uff0c\u7a7a\u6570\u7ec4\uff0cfalse\uff0c&#8217;0&#8217;\uff0cnull\uff0c\u672a\u5b9a\u4e49\u53d8\u91cf<br \/>\u8fd9\u51e0\u79cd\u8fd4\u56de true\uff0c\u5176\u4ed6\u90fd\u662f false<br \/>\u6bd5\u7adf object \u5224\u65ad\u662f\u6bd4\u8f83\u590d\u6742\u7684\uff0c\u9664\u975e\u65b0\u589e\u4e00\u4e2a__empty \u9b54\u672f\u65b9\u6cd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406761\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jhdxr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4f5c\u4e3a\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5224\u65ad empty \u975e\u7a7a\uff0c\u6211\u89c9\u5f97\u6ca1\u5565\u4e0d\u7b26\u5408\u76f4\u89c9\u7684\u3002\u5927\u6982\u60f3\u4e86\u60f3\u597d\u50cf\u6ca1\u5565\u8bed\u8a00\u4f1a\u9ed8\u8ba4\u63d0\u4f9b\u4e00\u4e2a\u5224\u65ad object \u4e3a\u7a7a\u7684\u60c5\u51b5\uff1f<\/p>\n<p>JSON.parse(&#8216;{}&#8217;)==null<br \/>false                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406762\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jhdxr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u300e\u4e0d\u533a\u5206 map \u548c list\uff0c\u770b\u4f3c\u5f88\u7075\u6d3b\uff0c\u4f46\u540c\u65f6\u4e5f\u6709\u4e0d\u5c11\u5751\u300f\u8fd9\u53e5\u8bdd\u6211\u4e0d\u53cd\u5bf9\uff0c\u5728\u505a spread operator \u76f8\u5173\u7684\u4e1c\u897f\u7684\u65f6\u5019\u7684\u786e\u5c31\u6389\u8fdb\u53bb\u8fc7\u3002<\/p>\n<p>\u4f46\u662f\u5c31\u4f60\u8fd9\u4e2a\u5e16\u5b50\uff0c\u4f60\u6df7\u6dc6\u4e86 map \u548c object                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406763\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @jhdxr \u56e0\u4e3a PHP \u4e2d\u60f3\u8981 json_encode \u4e4b\u540e\u5f97\u5230{}\u800c\u4e0d\u662f[]\uff0c\u6700\u7b80\u4fbf\u7684\u65b9\u5f0f\u5c31\u662f\u7528 object\uff0c\u4e0d\u7ba1\u662f(object)[]\u8fd8\u662f new stdClass \u6216 new class{}\uff0c\u7c7b\u578b\u5c31\u53d8\u6210\u4e86 array | object\uff0c\u57cb\u4e0b\u4e86\u4e00\u4e2a\u5751\u3002\u51e0\u5c42\u8c03\u7528\u4e4b\u540e\uff0c\u540e\u9762\u7684\u4eba\u5bb9\u6613\u5ffd\u89c6\u6389\u8fd9\u4e2a\u7ec6\u8282\u3002<\/p>\n<p>\u67d0\u4e9b PHP \u9879\u76ee\u4e3a\u4e86\u907f\u514d\u8fd9\u4e2a\u9ebb\u70e6\uff0c\u5e72\u8106\u7ea6\u5b9a JSON \u4e2d\u6240\u6709\u503c\u4e3a[]\u6216{}\u7684\u5b57\u6bb5\u90fd\u4f20 null \u6216\u4e0d\u5305\u542b\u8fd9\u4e2a\u5b57\u6bb5\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406764\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : jhdxr <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sagaxu \u5728\u6211\u7684\u7406\u89e3\u4e2d\uff0cjson_encode \u67d0\u79cd\u610f\u4e49\u4e0a\u4e5f\u5df2\u7ecf\u662f view \u5c42\u7684\u4e1c\u897f\uff0c\u90a3\u4e48\u6709\u8bf8\u5982\u67d0\u4e9b\u5b57\u6bb5\u5e94\u8be5\u662f map \u800c\u975e array \u8fd9\u79cd\u9650\u5236\u4e5f\u5e94\u8be5\u5728\u8fd9\u4e00\u5c42\u53bb\u505a\u6389\uff0c\u800c\u975e\u76f4\u63a5\u901a\u8fc7\u4fee\u6539\u539f\u59cb\u7684\u6570\u636e\u53bb\u5b9e\u73b0\u3002<\/p>\n<p>\u4f20 null \u8fd9\u4e2a\u65b9\u6848\u4e2a\u4eba\u8ba4\u4e3a\u975e\u5e38\u4e0d\u59a5\uff0c\u4e24\u8005\u7684\u8bed\u4e49\u4e0d\u5b8c\u5168\u76f8\u540c                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406765\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : DavidNineRoc <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3b\u8fd9\u79cd\u53ea\u4f20\u9012\u4e00\u4e2a {} \u6211\u662f\u6ca1\u770b\u61c2,\u4e3a\u4ec0\u4e48\u4f60\u7684\u8fd9\u4e2a\u8bed\u4e49\u5c31\u597d\u4e86.<br \/>\u4e2a\u4eba\u8ba4\u4e3a\u6b63\u786e\u7684<br \/>\/\/ \u6b63\u5e38<br \/>{<br \/> &#8220;data&#8221;: {<br \/> &#8220;id&#8221;: 1,<br \/> &#8220;name: &#8220;foo&#8221;<br \/>}<br \/>}<\/p>\n<p>\/\/ \u7a7a\u5bf9\u8c61<br \/>{<br \/>&#8220;data&#8221;: {<br \/> \/\/ \u540c\u7c7b\u578b<br \/> &#8220;id&#8221;: null or -1,<br \/> &#8220;name&#8221;: &#8220;&#8221;,<br \/>}<br \/>}<\/p>\n<p>\/\/ \u4e3b\u7684, \u8fd9\u4e2a\u8ba9\u524d\u7aef\u600e\u4e48\u5224\u65ad, getAttribute \u4e4b\u524d\u5148 if exists ?<br \/>{<br \/>&#8220;data&#8221;: {<\/p>\n<p>}<br \/>}<\/p>\n<p>\/\/ \u8fd8\u4e0d\u5982\u76f4\u63a5\u7ed9\u4e2a null, \u524d\u7aef\u77e5\u9053\u4e0d\u7528\u89e3\u6790\u4e86<br \/>{<br \/> &#8220;data&#8221;: null,<br \/>}<\/p>\n<p>\u4e0d\u8fc7\u6bcf\u79cd\u65b9\u6cd5\u90fd\u53ef\u4ee5,\u4e00\u5207\u6700\u91cd\u8981\u7684\u662f\u7ea6\u5b9a.                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406766\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bf4\u767d\u4e86 php \u5c31\u662f\u5751\uff0c\uff5b\uff5d\u5728 json_decode \u4e4b\u540e\u4f1a\u53d8\u6210[]\uff0c\u6ca1\u5f97\u6d17\uff0c\u6240\u4ee5\u6709\u65f6\u5019\u6211\u4eec\u5bf9\u4e8e\u52a8\u6001\u7ed3\u6784\u7684 json \u90fd\u662f\u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32\u7ed9\u524d\u7aef\uff0c\u8ba9\u4ed6\u4eec\u89e3\u6790                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406767\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @DavidNineRoc <br \/>prop \u53ef\u80fd\u662f 0 \u4e2a\u4e5f\u53ef\u80fd\u662f\u51e0\u5341\u4e2a<br \/>{<br \/>prop1: value1,<br \/>prop2: value2,<br \/>&#8230;<br \/>}\uff0c0 \u4e2a\u5c5e\u6027\uff0c\u7528{}\u662f\u5f88\u7b26\u5408\u9884\u671f\u7684<br \/>\u53e6\u4e00\u79cd\u65b9\u5f0f\u6253\u6563\u6210 list<br \/>[<br \/>{name:prop1, value:value1},<br \/>{name:prop2, value:value2},<br \/>]\uff0c\u7136\u540e\u7531\u8c03\u7528\u8005\u81ea\u5df1\u7ec4\u88c5\u6210 map \u6216 object \u4f7f\u7528\uff0c\u7136\u540e\u7528[]\u8868\u793a 0 \u4e2a<br \/>@jhdxr \u6709\u65f6\u5019\u53ea\u662f\u8f6c\u53d1\u548c\u7b80\u5355\u7ef4\u62a4\uff0c\u6bd4\u5982\u67d0\u4e2a\u4e2d\u95f4\u4ef6\uff0c\u5bf9\u5177\u4f53\u6570\u636e\u7ed3\u6784\u662f\u4e0d\u77e5\u60c5\u7684\uff0c\u53ea\u77e5\u9053\u4e00\u4e9b common \u7684\u5b57\u6bb5\uff0cdecode \u540e\u7a0d\u5fae\u6539\u6539\u518d encode \u56de\u6765\uff0c\u78b0\u5230{}\u53d8[]\u7684\u60c5\u51b5\uff0c\u5c31\u4e0d\u80fd\u7b80\u5355\u5904\u7406\u4e86\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406768\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : NjcyNzMzNDQ3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sagaxu<br \/>1 \u3001\u89e3\u51b3\u4e3b\u4e0d\u60f3\u8fd4\u56de NULL\uff0c\u4e0d\u7528\u4f60\u8d39\u529b empty\uff0c\u53e6\u5916 json \u91cc\u201c[]\uff0c{}\u201d\u4e0d\u5f71\u54cd\u524d\u7aef\u505a\u5224\u65ad<\/p>\n<p>&lt;?php<\/p>\n<p>$linksArray = [1, 4, &#8220;0&#8221;, &#8220;V&#8221;, null, false, true, &#8216;true&#8217;, &#8220;N&#8221;];<br \/>var_dump(json_encode(array_map(&#8216;strval&#8217;, $linksArray)));<\/p>\n<p>@JJstyle <br \/>1 \u3001\uff5b\uff5d\u5728 json_decode \u4e4b\u540e\u4f1a\u53d8\u6210 []\uff0cemm\uff0cphp \u9ed8\u8ba4\u89e3\u6790 object \u7684<br \/>2 \u3001\u52a8\u6001\u89e3\u6790\u7684 json \u76f4\u63a5\u8fd4\u56de\u5b57\u7b26\u4e32\uff0c\u8ba9\u524d\u7aef\u5224\u65ad\u662f\u5426\u662f\u5b57\u7b26\u4e32\u6216\u8005\u662f JSON\uff0c\u8fd9\u64cd\u4f5c\u771f\u662f\u770b\u4e0d\u61c2\u3002\u6211\u8ba4\u4e3a\u5728\u5236\u8ba2 API \u3001\u6570\u636e\u7ed3\u6784\u65f6\u5c31\u80fd\u89e3\u51b3\u8fd9\u4e9b\u5947\u602a\u7684\u95ee\u9898\u3002<\/p>\n<p>&lt;?php<\/p>\n<p>\/\/ default object <br \/>var_dump(json_decode(&#8216;{}&#8217;)); \/\/ object(stdClass)#1 (0) { }<\/p>\n<p>\/\/ array<br \/>var_dump(json_decode(&#8216;{}&#8217;, true)); \/\/ array(0) { }<\/p>\n<p>\u6700\u540e\u8bf4\u4e00\u70b9\u8bed\u8a00\u90fd\u6709\u5b58\u5728\u7684\u9053\u7406\uff0c\u4e0d\u8981\u6367\u4e00\u4e2a\u8bed\u8a00\u8e29\u4e00\u4e2a\u8bed\u8a00\uff0c\u6211\u8ba4\u4e3a\u8fd9\u4e2a\u884c\u4e3a\u5f88 low                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406769\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brader <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JJstyle \u4f60\u4ed4\u7ec6\u4e86\u89e3\u8fc7 php \u7684 json_encode \u51fd\u6570\u4e86\u5417\uff1f\u770b\u624b\u518c\u4e86\u5417\uff1f\u8fd9\u53e5\u8bdd\u4e5f\u9001\u7ed9\u4e0a\u7684\u4e00\u4e9b\u4eba\u3002<br \/>\u9ebb\u70e6\u53bb\u770b\u770b json_encode \u7684 JSON_FORCE_OBJECT \u53c2\u6570\u597d\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406770\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @NjcyNzMzNDQ3 \u524d\u7aef\u4e0d\u4ec5\u4ec5\u662f js\uff0c\u8fd8\u6709\u5ba2\u6237\u7aef\uff0c\u7c7b\u578b\u4e0d\u5339\u914d\u89e3\u6790\u4f1a\u62a5\u9519                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406771\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : pinews <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u4e3b\uff0c\u8bf4\u6e05\u695a\u4f60\u5230\u5e95\u60f3\u600e\u4e48\u6837\uff1f php \u662f\u5f31\u7c7b\u8bed\u8a00\uff0c\u5f88\u591a\u65f6\u5019\u662f\u4f18\u52bf\uff0c\u4f60\u975e\u8981\u53cd\u8fc7\u6765\u628a\u4f18\u52bf\u5f53\u52a3\u52bf\u7528\uff0c\u8981\u4e0d\u7528===\uff0c\u65e2\u7136\u662f\u4e0d\u719f\u6089\u7684\u5730\u65b9\uff0c\u5c31\u522b\u8d38\u7136\u7528==                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406772\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @brader \u4e24\u4e2a\u7a7a\u6570\u7ec4\uff0c\u4e00\u4e2a\u8981\u5e8f\u5217\u5316\u6210[]\uff0c\u53e6\u4e00\u4e2a\u8981{}\uff0cforceobject \u4e00\u5200\u5207\u663e\u7136\u662f\u4e0d\u884c\u7684                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406773\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brader <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sagaxu \u5b8c\u5168\u6ca1\u6709\u95ee\u9898\u597d\u5417\uff1f\u4f60\u53ef\u4ee5\u53bb\u6d4b\u8bd5                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406774\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brader <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sagaxu <br \/>$b = &#8216;{&#8220;a&#8221;:1,&#8221;b&#8221;:{},&#8221;c&#8221;:[]}&#8217;;<br \/>$b = json_decode($b);<br \/>$b = json_encode($b);<\/p>\n<p>\u53cd\u5e8f\u5217\u5316\u548c\u5e8f\u5217\u5316\u51fa\u6765\u7684\u5b57\u7b26\u4e32\uff0c\u4e00\u6837\u7684                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406775\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Erroad <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @brader \u4f60\u8bb2\u7684\u9053\u7406\u90fd\u6ca1\u9519\uff0c\u4f46\u662f\u4eba\u5bb6\u95ee\u7684\u662f&#8221;\u4e24\u4e2a\u7a7a\u6570\u7ec4\uff0c\u4e00\u4e2a\u8981\u5e8f\u5217\u5316\u6210[]\uff0c\u53e6\u4e00\u4e2a\u8981{}&#8221;                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406776\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brader <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Erroad \u9700\u8981\u5e8f\u5217\u5316\u6210{}\u7684\uff0c\u52a0 JSON_FORCE_OBJECT \u53c2\u6570\u4e0d\u5c31\u597d\u4e86\u5417\uff1f<br \/>\u5982\u679c\u662f\u5728\u4e00\u4e2a\u5730\u65b9\u6709[]\u548c{}\u7684\uff0c\u90a3\u5728\u5e8f\u5217\u5316\u524d\u4fdd\u6301\u597d\u6570\u636e\u7c7b\u578b\u4e0d\u5c31\u5bf9\u4e86\uff1f\u6709\u4ec0\u4e48\u95ee\u9898\u5462                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406777\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : sagaxu <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @brader \u628a map \u90fd decode \u6210 stdClass \u4e5f\u662f\u4e00\u79cd\u529e\u6cd5\uff0c\u4f46\u8ddf\u7528(object)[]\u8868\u793a{}\u6ca1\u4ec0\u4e48\u4e0d\u540c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406778\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brader <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @sagaxu \u4f60\u8bf4\u5199\u6cd5\u95ee\u9898\u7684\u8bdd\uff0c\u6211\u89c9\u5f97(object)[]\u6ca1\u5565\u4e0d\u597d\u7684\uff0c\u8fd9\u4e2a\u8bed\u610f\u975e\u5e38\u660e\u786e\uff0c\u4ee3\u7801\u53ef\u8bfb\u6027\u4e5f\u597d\uff0c\u4f46\u7b80\u6d01\u6027\u6709\u5f85\u52a0\u5f3a\uff0c\u5728\u5b98\u65b9\u8fd8\u4e0d\u652f\u6301{}\u7684\u5199\u6cd5\u4e4b\u524d\uff0c\u6211\u4eec\u53ea\u80fd\u8fd9\u4e48\u5199\uff0c\u4f60\u60f3\u6539\u53d8\u4ed6\uff0c\u53ef\u4ee5\u63d0\u8bae\u3002<\/p>\n<p>\u4f60\u8981\u60f3\u60f3\uff0c\u4ee5\u524d\u6570\u7ec4\uff0c\u8fd8\u8981\u5199 array()\u5462\uff0c\u73b0\u5728\u53d8\u6210[]\uff0c\u4e0d\u5c31\u662f\u6709\u4e9b\u81f4\u529b\u6539\u53d8\u5b83\u7684\u4eba\u7684\u52aa\u529b\u5417                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406779\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @brader \u6211\u9700\u8981\u7684\u662f\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4\uff0c\u800c\u52a0\u4e0a\u53c2\u6570\u540e\u53d8\u6210\u4e86\u4e00\u4e2a\u5bf9\u8c61\uff1a<\/p>\n<p>https:\/\/gist.github.com\/Jaggle\/9338af5321d3294d86d350fd2cad0fc9 <button onclick=\"lazyGist(this)\">\u00a0\u663e\u793a Gist \u4ee3\u7801\u00a0<\/button> <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406780\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @NjcyNzMzNDQ3 \u6211\u4eec\u6709\u4e00\u4e2a json \u7684\u914d\u7f6e\u6570\u636e\uff0c\u5b58\u5728\u6570\u636e\u5e93\u91cc\uff0c\u9996\u5148\uff0c\u89e3\u6790\u540e\u4ed6\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u8fd9\u65f6\u8fdb\u884c json_decode($json, true)\uff0c\u6ca1\u95ee\u9898\uff0c\u4f46\u662f\u4ed6\u7684\u5143\u7d20\u662f\u90fd\u662f object\uff0c\u800c object \u5c31\u5e94\u8be5 decode \u6210 object<\/p>\n<p>u1s1\uff0c\u6211\u8e29 php \u4e86\uff1f\u6211\u53c8\u6367\u4e86\u54ea\u4e2a\u8bed\u8a00\uff1f                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406781\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : oooooooooooo <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             map \u548c list \u4e0d\u533a\u5206\u786e\u5b9e\u5f88 SB                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406782\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : NjcyNzMzNDQ3 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JJstyle \u5fd8\u8bb0\u52a0\u65ad\u884c\u4e86\uff0c\u53ea\u662f\u53e5\u5410\u69fd\uff0c\u6ca1\u6709\u7279\u522b\u9488\u5bf9\u67d0\u4e2a\u4eba                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406783\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brader <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JJstyle \u4e0d\u7406\u89e3\u4f60\u7684\u5bf9\u8c61\u6570\u7ec4\u662f\u4ec0\u4e48\u610f\u601d\uff1f\u4f60\u5199\u51fa\u4f60\u6240\u8c13\u7684\u5bf9\u8c61\u6570\u7ec4\u7684 json \u4e32\u5417\uff1f                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406784\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : brader <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JJstyle \u8fd8\u6709\u4f60\u524d\u9762\u8bf4\u7684 \uff5b\uff5d\u5728 json_decode \u4e4b\u540e\u4f1a\u53d8\u6210[]\uff0c<br \/>\u6211\u5c1d\u8bd5\u4e86\u4e00\u4e0b\uff0c\u5e76\u4e0d\u662f\u8fd9\u6837\u7684<\/p>\n<p>$str = &#8216;[{},{}]&#8217;;<br \/>$data = json_decode($str);<br \/>var_dump($data);<br \/>\u8f93\u51fa\uff1a<br \/>array(2) {<br \/> [0] =&gt;<br \/> class stdClass#153 (0) {<br \/> }<br \/> [1] =&gt;<br \/> class stdClass#154 (0) {<br \/> }<br \/>}<\/p>\n<p>php \u7248\u672c 7.2.1                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406785\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @brader #23 \u4e2d\u7684\u7b2c\u4e00\u4e2a ouput \u5c31\u662f\u4e00\u4e2a\u5bf9\u8c61\u6570\u7ec4\uff08\u81ea\u8eab\u662f\u4e00\u4e2a\u6570\u7ec4\uff0c\u5b83\u7684\u6bcf\u4e2a\u5143\u7d20\u662f\u4e00\u4e2a\u5bf9\u8c61\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406786\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : lovecy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @JJstyle \u4f60\u7684 json_decode\uff0c\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f true \u624d\u4f1a\u628a{}\u89e3\u6790\u6210 array()\uff0c\u5b98\u65b9\u6587\u6863\u662f\u8fd9\u4e48\u5199\u7684<br \/>&#8220;`\u5f53\u8be5\u53c2\u6570\u4e3a TRUE \u65f6\uff0c\u5c06\u8fd4\u56de array \u800c\u975e object &#8220;`<br \/>\u8bf4\u767d\u4e86\u4f60\u81ea\u5df1\u7528\u7684\u65b9\u5f0f\u4e0d\u5bf9\uff0c\u5728\u8fd9\u91cc\u62b9\u9ed1                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406787\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : yc8332 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u91cd\u6765\u6ca1\u8fd9\u4e48\u5199\u8fc7\u3002\u3002\u8981\u7a7a\u5bf9\u8c61\u5c31\u7528 new stdClass                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"2406788\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : JJstyle <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @lovecy <br \/>@brader <br \/>@NjcyNzMzNDQ3 <\/p>\n<p>\u6211\u8bef\u602a json_decode \u8fd9\u4e2a\u51fd\u6570\u4e86\uff0c\u672c\u8d28\u4e0a\u662f\u56e0\u4e3a laravel \u5728\u63a5\u6536\u53c2\u6570\u65f6\uff0c\u9ed8\u8ba4\u7528\u7684 json_decode($request, true)\u89e3\u6790\u53c2\u6570\uff0c\u56e0\u6b64\u5b83\u4f1a\u628a{} decode \u6210 []\uff0c\u5e76\u975e\u62b9\u9ed1\uff0c\u53ea\u662f\u88ab\u5751\u8fc7\u6709\u70b9\u607c\u706b\u3002<\/p>\n<p>\u89e3\u51b3\u529e\u6cd5\u662f 1. \u9488\u5bf9\u7279\u5b9a\u63a5\u53e3\u4f7f\u7528 json_decode($request, false)\u89e3\u6790\u53c2\u6570\u4e3a object\uff0c2. \u52a8\u6001 json \u5b57\u6bb5\u4f7f\u7528\u5b57\u7b26\u4e32\u4f20\u8f93\uff0c\u4f9d\u7136\u4f7f\u7528 json_decode($request, true)\u89e3\u6790\u53c2\u6570\u4e3a array \u3002\u6211\u4eec\u9009\u62e9\u4e86\u7b2c\u4e8c\u79cd\u65b9\u6848\u3002<\/p>\n<p>\u6211\u7684\u9505\u6211\u7684\u9505\u6211\u7684\u9505                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u91cc empty((obje&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134984"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=134984"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/134984\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=134984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=134984"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=134984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}