{"id":47116,"date":"2024-12-02T12:38:20","date_gmt":"2024-12-02T04:38:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/47116\/"},"modified":"2024-12-02T12:38:20","modified_gmt":"2024-12-02T04:38:20","slug":"php-%e5%8c%bf%e5%90%8d%e5%87%bd%e6%95%b0%e5%9c%a8%e5%a4%84%e7%90%86%e6%95%b0%e6%8d%ae%e7%bb%93%e6%9e%84%e4%b8%ad%e7%9a%84%e5%ba%94%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/47116\/","title":{"rendered":"PHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>PHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528<\/h1>\n<p>\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aPHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528\u300b<\/span>\u5c06\u4f1a\u4ecb\u7ecd\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<p>PHP \u533f\u540d\u51fd\u6570\u5728\u6570\u636e\u7ed3\u6784\u5904\u7406\u4e2d\u7684\u5e94\u7528\uff1a\u8f7b\u677e\u5904\u7406\u6570\u7ec4\uff0c\u4f8b\u5982\u901a\u8fc7\u533f\u540d\u51fd\u6570\u6392\u5e8f\u3002\u65b9\u4fbf\u5904\u7406\u5bf9\u8c61\uff0c\u4f8b\u5982\u901a\u8fc7\u533f\u540d\u51fd\u6570\u7b5b\u9009\u6ee1\u8db3\u6761\u4ef6\u7684\u5bf9\u8c61\u3002\u5728\u5904\u7406 MySQL \u67e5\u8be2\u7ed3\u679c\u65f6\u63d0\u4f9b\u7075\u6d3b\u6027\u548c\u7b80\u4fbf\u6027\uff0c\u4f8b\u5982\u533f\u540d\u51fd\u6570\u53ef\u7528\u4e8e\u63d0\u53d6\u7279\u5b9a\u5217\u6570\u636e\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241025\/1729866754671bac02e4d9c.jpg\" class=\"aligncenter\" title=\"PHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528\u63d2\u56fe\" alt=\"PHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528<\/strong><\/p>\n<p><strong>\u5f15\u8a00<\/strong><\/p>\n<p>\u533f\u540d\u51fd\u6570\uff0c\u4e5f\u79f0\u4e3a\u95ed\u5305\uff0c\u662f PHP \u4e2d\u4e00\u79cd\u5f3a\u5927\u7684\u51fd\u6570\uff0c\u5b83\u5141\u8bb8\u5728\u4e0d\u5b9a\u4e49\u7279\u5b9a\u51fd\u6570\u540d\u79f0\u7684\u60c5\u51b5\u4e0b\u5b9a\u4e49\u548c\u8c03\u7528\u51fd\u6570\u3002\u8fd9\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u65f6\u7279\u522b\u6709\u7528\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u3001\u66f4\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u64cd\u4f5c\u6570\u636e\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>$anonymousFunction = function ($parameters) use ($variables) {\n    \/\/ \u51fd\u6570\u4f53\n};<\/pre>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li><code>$anonymousFunction<\/code> \u662f\u533f\u540d\u51fd\u6570\u7684\u540d\u79f0\uff08\u53ef\u9009\uff09<\/li>\n<li><code>$parameters<\/code> \u662f\u533f\u540d\u51fd\u6570\u7684\u53c2\u6570<\/li>\n<li><code>use ($variables)<\/code> \u5141\u8bb8\u8bbf\u95ee\u5916\u90e8\u53d8\u91cf<\/li>\n<\/ul>\n<p><strong>\u5904\u7406\u6570\u7ec4<\/strong><\/p>\n<p>\u533f\u540d\u51fd\u6570\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u7528\u6765\u5904\u7406\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u533f\u540d\u51fd\u6570\u6765\u5bf9\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1a<\/p>\n<pre>$numbers = [1, 3, 5, 2, 4];\n\nusort($numbers, function ($a, $b) {\n    return $a - $b;\n});\n\nprint_r($numbers); \/\/ [1, 2, 3, 4, 5]<\/pre>\n<p><strong>\u5904\u7406\u5bf9\u8c61<\/strong><\/p>\n<p>\u533f\u540d\u51fd\u6570\u4e5f\u53ef\u4ee5\u7528\u6765\u5904\u7406\u5bf9\u8c61\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u533f\u540d\u51fd\u6570\u6765\u4ece\u5bf9\u8c61\u96c6\u5408\u4e2d\u8fc7\u6ee4\u51fa\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u5bf9\u8c61\uff1a<\/p>\n<pre>$users = [\n    ['name' =&gt; 'John', 'age' =&gt; 25],\n    ['name' =&gt; 'Mary', 'age' =&gt; 30],\n    ['name' =&gt; 'Bob', 'age' =&gt; 22],\n];\n\n$filteredUsers = array_filter($users, function ($user) {\n    return $user['age'] &gt; 25;\n});\n\nprint_r($filteredUsers); \/\/ [{'name' =&gt; 'Mary', 'age' =&gt; 30}]<\/pre>\n<p><strong>\u5b9e\u65f6\u6848\u4f8b<\/strong><\/p>\n<p><strong>\u4f7f\u7528\u533f\u540d\u51fd\u6570\u4e0e MySQL \u67e5\u8be2\u7ed3\u679c\u4ea4\u4e92<\/strong><\/p>\n<p>\u5728\u5904\u7406 MySQL \u67e5\u8be2\u7ed3\u679c\u65f6\uff0c\u533f\u540d\u51fd\u6570\u53ef\u4ee5\u63d0\u4f9b\u7075\u6d3b\u6027\u548c\u7b80\u4fbf\u6027\u3002\u8003\u8651\u4ee5\u4e0b\u793a\u4f8b\uff1a<\/p>\n<pre>$pdo = new PDO('mysql:host=localhost;dbname=database', 'username', 'password');\n$statement = $pdo-&gt;prepare('SELECT * FROM table');\n$statement-&gt;execute();\n\n$results = $statement-&gt;fetchAll(PDO::FETCH_ASSOC);\n\n$names = array_map(function ($row) {\n    return $row['name'];\n}, $results);\n\nprint_r($names); \/\/ ['John', 'Mary', 'Bob']<\/pre>\n<p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u533f\u540d\u51fd\u6570\u7528\u4e8e\u4ece\u67e5\u8be2\u7ed3\u679c\u4e2d\u63d0\u53d6\u540d\u79f0\u5e76\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u8fd9\u4e9b\u540d\u79f0\u7684\u6570\u7ec4\u3002<\/p>\n<p><strong>\u7ed3\u8bba<\/strong><\/p>\n<p>PHP \u533f\u540d\u51fd\u6570\u662f\u5904\u7406\u6570\u636e\u7ed3\u6784\u65f6\u7684\u4e00\u9879\u5f3a\u5927\u5de5\u5177\u3002\u5b83\u4eec\u63d0\u4f9b\u4e86\u7b80\u6d01\u6027\u548c\u7075\u6d3b\u6027\uff0c\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u4ee5\u66f4\u6709\u6548\u7684\u65b9\u5f0f\u64cd\u4f5c\u6570\u636e\u3002<\/p>\n<p>\u6587\u4e2d\u5173\u4e8ephp,\u533f\u540d\u51fd\u6570\u7684\u77e5\u8bc6\u4ecb\u7ecd\uff0c\u5e0c\u671b\u5bf9\u4f60\u7684\u5b66\u4e60\u6709\u6240\u5e2e\u52a9\uff01\u82e5\u662f\u53d7\u76ca\u532a\u6d45\uff0c\u90a3\u5c31\u52a8\u52a8\u9f20\u6807\u6536\u85cf\u8fd9\u7bc7\u300aPHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528\u300b\u6587\u7ae0\u5427\uff0c\u4e5f\u53ef\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\u4e86\u89e3\u76f8\u5173\u6280\u672f\u6587\u7ae0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>PHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528 \u5b66\u4e60\u6587\u7ae0\u8981\u52aa\u529b\uff0c\u4f46\u662f\u4e0d\u8981\u6025\uff01\u4eca\u5929\u7684\u8fd9\u7bc7\u6587\u7ae0\u300aPHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528\u300b\u5c06\u4f1a\u4ecb\u7ecd\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u5982\u679c\u4f60\u60f3\u6df1\u5165\u5b66\u4e60\u6587\u7ae0\uff0c\u53ef\u4ee5\u5173\u6ce8\u6211\uff01\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\u7684\uff0c\u5e0c\u671b\u5bf9\u5927\u5bb6\u90fd\u80fd\u6709\u6240\u5e2e\u52a9\uff01 PHP \u533f\u540d\u51fd\u6570\u5728\u6570\u636e\u7ed3\u6784\u5904\u7406\u4e2d\u7684\u5e94\u7528\uff1a\u8f7b\u677e\u5904\u7406\u6570\u7ec4\uff0c\u4f8b\u5982\u901a\u8fc7\u533f\u540d\u51fd\u6570\u6392\u5e8f\u3002\u65b9\u4fbf\u5904\u7406\u5bf9\u8c61\uff0c\u4f8b\u5982\u901a\u8fc7\u533f\u540d\u51fd\u6570\u7b5b\u9009\u6ee1\u8db3\u6761\u4ef6\u7684\u5bf9\u8c61\u3002\u5728\u5904\u7406 MySQL \u67e5\u8be2\u7ed3\u679c\u65f6\u63d0\u4f9b\u7075\u6d3b\u6027\u548c\u7b80\u4fbf\u6027\uff0c\u4f8b\u5982\u533f\u540d\u51fd\u6570\u53ef\u7528\u4e8e\u63d0\u53d6\u7279\u5b9a\u5217\u6570\u636e\u3002 PHP \u533f\u540d\u51fd\u6570\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u4e2d\u7684\u5e94\u7528 \u5f15\u8a00 \u533f\u540d\u51fd\u6570\uff0c\u4e5f\u79f0\u4e3a\u95ed\u5305\uff0c\u662f PHP \u4e2d\u4e00\u79cd\u5f3a\u5927\u7684\u51fd\u6570\uff0c\u5b83\u5141\u8bb8\u5728\u4e0d\u5b9a\u4e49\u7279\u5b9a\u51fd\u6570\u540d\u79f0\u7684\u60c5\u51b5\u4e0b\u5b9a\u4e49\u548c\u8c03\u7528\u51fd\u6570\u3002\u8fd9\u5728\u5904\u7406\u6570\u636e\u7ed3\u6784\u65f6\u7279\u522b\u6709\u7528\uff0c\u56e0\u4e3a\u5b83\u63d0\u4f9b\u4e86\u66f4\u7b80\u6d01\u3001\u66f4\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u64cd\u4f5c\u6570\u636e\u3002 \u8bed\u6cd5 \u521b\u5efa\u4e00\u4e2a\u533f\u540d\u51fd\u6570\u7684\u8bed\u6cd5\u5982\u4e0b\uff1a $anonymousFunction = function ($parameters) use ($variables) { \/\/ \u51fd\u6570\u4f53 }; \u5176\u4e2d\uff1a $anonymousFunction \u662f\u533f\u540d\u51fd\u6570\u7684\u540d\u79f0\uff08\u53ef\u9009\uff09 $parameters \u662f\u533f\u540d\u51fd\u6570\u7684\u53c2\u6570 use ($variables) \u5141\u8bb8\u8bbf\u95ee\u5916\u90e8\u53d8\u91cf \u5904\u7406\u6570\u7ec4 \u533f\u540d\u51fd\u6570\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u7528\u6765\u5904\u7406\u6570\u7ec4\u3002\u4f8b\u5982\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u533f\u540d\u51fd\u6570\u6765\u5bf9\u6570\u7ec4\u5143\u7d20\u8fdb\u884c\u6392\u5e8f\uff1a $numbers = [1, 3, 5, 2, 4]; usort($numbers, function ($a, $b) { return $a &#8211; $b; }); print_r($numbers); \/\/ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-47116","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47116","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=47116"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/47116\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=47116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=47116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=47116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}