{"id":49593,"date":"2023-08-20T20:11:32","date_gmt":"2023-08-20T12:11:32","guid":{"rendered":"https:\/\/docs.pingcode.com\/?p=49593"},"modified":"2023-08-20T20:11:34","modified_gmt":"2023-08-20T12:11:34","slug":"%e5%86%99php%e4%bb%a3%e7%a0%81%e7%9a%84%e6%97%b6%e5%80%99%ef%bc%8c%e4%bb%80%e4%b9%88%e6%98%af%e9%97%ad%e5%8c%85%e5%92%8c%e5%8c%bf%e5%90%8d%e5%87%bd%e6%95%b0","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/49593.html","title":{"rendered":"\u5199PHP\u4ee3\u7801\u7684\u65f6\u5019\uff0c\u4ec0\u4e48\u662f\u95ed\u5305\u548c\u533f\u540d\u51fd\u6570"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote\">\n<p>\u5728PHP\u7f16\u7a0b\u4e2d\uff0c<strong>\u95ed\u5305<\/strong>\u548c<strong>\u533f\u540d\u51fd\u6570<\/strong>\u662f\u4e24\u4e2a\u76f8\u5173\u4f46\u4e0d\u5b8c\u5168\u76f8\u540c\u7684\u6982\u5ff5\u3002<strong>1\u3001\u533f\u540d\u51fd\u6570<\/strong>\u662f\u6307\u6ca1\u6709\u540d\u79f0\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u8d4b\u503c\u7ed9\u53d8\u91cf\u6216\u4f5c\u4e3a\u53c2\u6570\u4f20\u9012\uff1b<strong>2\u3001\u95ed\u5305<\/strong>\u662f\u4e00\u4e2a\u7279\u6b8a\u7c7b\u578b\u7684\u533f\u540d\u51fd\u6570\uff0c\u5b83\u6355\u83b7\u4e86\u521b\u5efa\u5b83\u7684\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\u3002\u7b80\u5355\u6765\u8bf4\uff0c\u533f\u540d\u51fd\u6570\u7684\u7279\u70b9\u662f\u5b83\u6ca1\u6709\u540d\u5b57\uff0c\u65b9\u4fbf\u4f5c\u4e3a\u4e34\u65f6\u7684\u4ee3\u7801\u5757\u4f7f\u7528\uff0c\u800c\u95ed\u5305\u5219\u662f\u4e00\u79cd\u7279\u6b8a\u7684\u533f\u540d\u51fd\u6570\uff0c\u5b83\u80fd\u591f\u201c\u8bb0\u4f4f\u201d\u81ea\u5df1\u88ab\u521b\u5efa\u65f6\u7684\u73af\u5883\u3002<\/p>\n<\/blockquote>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"680\" height=\"421\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/08\/pingcode\u6b63\u6587-20-2.jpg?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\" class=\"wp-image-49596\" srcset=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/08\/pingcode\u6b63\u6587-20-2.jpg 680w, https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2023\/08\/pingcode\u6b63\u6587-20-2-300x186.jpg 300w\" sizes=\"(max-width: 680px) 100vw, 680px\" \/><\/figure><\/div>\n\n\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u533f\u540d\u51fd\u6570<\/h2>\n\n\n\n<p>\u533f\u540d\u51fd\u6570\u662f\u6ca1\u6709\u540d\u5b57\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u7528\u4f5c\u4e00\u6b21\u6027\u7684\u3001\u4e34\u65f6\u7684\u4ee3\u7801\u5757\u3002<\/p>\n\n\n\n<ul>\n<li><strong>\u521b\u5efa\u65b9\u6cd5<\/strong>: \u901a\u8fc7<code>function<\/code>\u5173\u952e\u5b57\u540e\u76f4\u63a5\u8ddf\u62ec\u53f7\u548c\u4ee3\u7801\u5757\u6765\u521b\u5efa\u3002<\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u573a\u666f<\/strong>: \u901a\u5e38\u7528\u4e8e\u56de\u8c03\u3001\u6570\u7ec4\u64cd\u4f5c\u6216\u5176\u4ed6\u4e00\u6b21\u6027\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$greet = function($name) {\r\n    return \"Hello, \" . $name;\r\n};\r\necho $greet('World'); \/\/ \u8f93\u51fa \"Hello, World\"\r<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001\u95ed\u5305<\/h2>\n\n\n\n<p>\u95ed\u5305\u662f\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684\u533f\u540d\u51fd\u6570\uff0c\u53ef\u4ee5\u6355\u83b7\u5176\u5916\u90e8\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\u3002<\/p>\n\n\n\n<ul>\n<li><strong>\u521b\u5efa\u65b9\u6cd5<\/strong>: \u540c\u533f\u540d\u51fd\u6570\uff0c\u4f46\u53ef\u4ee5\u901a\u8fc7<code>use<\/code>\u5173\u952e\u5b57\u6355\u83b7\u5916\u90e8\u53d8\u91cf\u3002<\/li>\n\n\n\n<li><strong>\u7279\u6027<\/strong>: \u95ed\u5305\u53ef\u4ee5\u201c\u8bb0\u4f4f\u201d\u5916\u90e8\u53d8\u91cf\u7684\u503c\uff0c\u5373\u4f7f\u5728\u51fd\u6570\u5916\u90e8\u4f5c\u7528\u57df\u6d88\u5931\u540e\u4e5f\u53ef\u4ee5\u8bbf\u95ee\u3002<\/li>\n<\/ul>\n\n\n\n<p><strong>\u793a\u4f8b\u4ee3\u7801<\/strong>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>$message = 'Hello, World';\r\n$example = function () use ($message) {\r\n    return $message;\r\n};\r\necho $example(); \/\/ \u8f93\u51fa \"Hello, World\"\r<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\" \/>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>\u5e38\u89c1\u95ee\u7b54<\/strong><\/h2>\n\n\n\n<ul>\n<li>Q1:<strong>\u533f\u540d\u51fd\u6570\u548c\u95ed\u5305\u6709\u4ec0\u4e48\u4e0d\u540c?<\/strong> <\/li>\n\n\n\n<li>A1:\u533f\u540d\u51fd\u6570\u662f\u6ca1\u6709\u540d\u5b57\u7684\u51fd\u6570\uff1b\u95ed\u5305\u662f\u53ef\u4ee5\u6355\u83b7\u5176\u5916\u90e8\u4f5c\u7528\u57df\u4e2d\u7684\u53d8\u91cf\u7684\u533f\u540d\u51fd\u6570\u3002<\/li>\n\n\n\n<li><strong>Q2:\u95ed\u5305\u5728PHP\u4e2d\u6709\u4ec0\u4e48\u7528\u9014?<\/strong> <\/li>\n\n\n\n<li>A2:\u95ed\u5305\u5e38\u7528\u4e8e\u56de\u8c03\u3001\u4e8b\u4ef6\u5904\u7406\u3001\u4f9d\u8d56\u6ce8\u5165\u7b49\uff0c\u80fd\u591f\u63d0\u9ad8\u4ee3\u7801\u7684\u7075\u6d3b\u6027\u548c\u5c01\u88c5\u6027\u3002<\/li>\n\n\n\n<li><strong>Q3:\u5982\u4f55\u5728\u95ed\u5305\u4e2d\u4fee\u6539\u5916\u90e8\u53d8\u91cf\u7684\u503c?<\/strong> <\/li>\n\n\n\n<li>A3:\u53ef\u4ee5\u5728<code>use<\/code>\u5173\u952e\u5b57\u540e\u7684\u53d8\u91cf\u524d\u52a0\u4e0a<code>&amp;<\/code>\u7b26\u53f7\uff0c\u8fd9\u6837\u5c31\u53ef\u4ee5\u901a\u8fc7\u5f15\u7528\u6765\u4fee\u6539\u5916\u90e8\u53d8\u91cf\u7684\u503c\u3002<\/li>\n\n\n\n<li><strong>Q4:PHP\u4e2d\u7684\u533f\u540d\u51fd\u6570\u53ef\u4ee5\u6709\u540d\u5b57\u5417?<\/strong> <\/li>\n\n\n\n<li>A4:\u4e00\u65e6\u7ed9\u533f\u540d\u51fd\u6570\u5206\u914d\u4e86\u540d\u5b57\u6216\u5b58\u50a8\u5728\u53d8\u91cf\u4e2d\uff0c\u5b83\u5c06\u5931\u53bb\u533f\u540d\u7684\u7279\u6027\u3002<\/li>\n\n\n\n<li><strong>Q5:\u95ed\u5305\u53ef\u4ee5\u6355\u83b7\u54ea\u4e9b\u7c7b\u578b\u7684\u53d8\u91cf?<\/strong> <\/li>\n\n\n\n<li>A5:\u95ed\u5305\u53ef\u4ee5\u6355\u83b7\u5176\u5916\u90e8\u4f5c\u7528\u57df\u4e2d\u7684\u4efb\u4f55\u7c7b\u578b\u7684\u53d8\u91cf\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u5728PHP\u7f16\u7a0b\u4e2d\uff0c\u95ed\u5305\u548c\u533f\u540d\u51fd\u6570\u662f\u4e24\u4e2a\u76f8\u5173\u4f46\u4e0d\u5b8c\u5168\u76f8\u540c\u7684\u6982\u5ff5\u30021\u3001\u533f\u540d\u51fd\u6570\u662f\u6307\u6ca1\u6709\u540d\u79f0\u7684\u51fd\u6570\uff0c\u53ef\u4ee5\u8d4b\u503c\u7ed9\u53d8\u91cf\u6216\u4f5c [&hellip;]","protected":false},"author":6,"featured_media":49594,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[1491,1492,1493],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/49593"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=49593"}],"version-history":[{"count":0,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/49593\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/49594"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=49593"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=49593"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=49593"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}