{"id":27501,"date":"2024-11-24T14:24:49","date_gmt":"2024-11-24T06:24:49","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27501\/"},"modified":"2024-11-24T14:24:49","modified_gmt":"2024-11-24T06:24:49","slug":"php%e4%b8%adif%e5%87%bd%e6%95%b0%e7%9a%84%e4%bd%bf%e7%94%a8%e6%96%b9%e6%b3%95%e6%98%af%e4%bb%80%e4%b9%88","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27501\/","title":{"rendered":"php\u4e2dif\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\u662f\u4ec0\u4e48"},"content":{"rendered":"<blockquote><p>\n  php if \u51fd\u6570\u7528\u4e8e\u6267\u884c\u6761\u4ef6\u8bed\u53e5\uff0c\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u4e3a\u771f\u3002\u8bed\u6cd5\uff1aif (condition) { \u8981\u6267\u884c\u7684\u4ee3\u7801\u5757}\u3002\u53c2\u6570\uff1acondition\uff08\u6761\u4ef6\uff09\u3002\u8fd4\u56de\u503c\uff1a\u771f\u6216\u5047\u3002\u5d4c\u5957 if \u8bed\u53e5\u53ef\u7528\u4e8e\u521b\u5efa\u66f4\u590d\u6742\u7684\u6761\u4ef6\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/11\/2024111100303281193.jpg\" class=\"aligncenter\" title=\"php\u4e2dif\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\u662f\u4ec0\u4e48\u63d2\u56fe\" alt=\"php\u4e2dif\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\u662f\u4ec0\u4e48\u63d2\u56fe\" \/><\/p>\n<p><strong>PHP if \u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5<\/strong><\/p>\n<p>if \u51fd\u6570\u5728 PHP \u4e2d\u7528\u4e8e\u6267\u884c\u6761\u4ef6\u8bed\u53e5\u3002\u5b83\u68c0\u67e5\u4e00\u4e2a\u6761\u4ef6\u662f\u5426\u4e3a true\uff0c\u5982\u679c\u4e3a true\uff0c\u5219\u6267\u884c\u6307\u5b9a\u4ee3\u7801\u5757\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>if (condition) {\n  \/\/ \u8981\u6267\u884c\u7684\u4ee3\u7801\u5757\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li>condition\uff1a\u8981\u8bc4\u4f30\u7684\u6761\u4ef6\u3002\u5b83\u53ef\u4ee5\u662f\u4efb\u4f55\u5e03\u5c14\u8868\u8fbe\u5f0f\u6216\u53d8\u91cf\u3002<\/li>\n<\/ul>\n<p><strong>\u8fd4\u56de\u503c\uff1a<\/strong><\/p>\n<p>if \u51fd\u6570\u8fd4\u56de true \u6216 false\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6761\u4ef6\u662f\u5426\u4e3a true\u3002<\/p>\n<p><strong>\u4f7f\u7528\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>$age = 18;\n\nif ($age &gt;= 18) {\n  echo \"\u60a8\u5df2\u6210\u5e74\";\n} else {\n  echo \"\u60a8\u672a\u6210\u5e74\";\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0cif \u51fd\u6570\u4f1a\u68c0\u67e5\u5e74\u9f84\u662f\u5426\u5927\u4e8e\u6216\u7b49\u4e8e 18 \u5c81\u3002\u5982\u679c\u662f\uff0c\u5219\u8f93\u51fa &#8220;\u60a8\u5df2\u6210\u5e74&#8221;\uff1b\u5426\u5219\uff0c\u8f93\u51fa &#8220;\u60a8\u672a\u6210\u5e74&#8221;\u3002<\/p>\n<p><strong>\u5d4c\u5957 if \u8bed\u53e5\uff1a<\/strong><\/p>\n<p>\u4f60\u53ef\u4ee5\u4f7f\u7528\u5d4c\u5957 if \u8bed\u53e5\u6765\u521b\u5efa\u66f4\u590d\u6742\u7684\u6761\u4ef6\uff1a<\/p>\n<pre>$age = 16;\n$gender = \"\u7537\";\n\nif ($age &gt;= 18) {\n  echo \"\u60a8\u5df2\u6210\u5e74\";\n} else if ($gender == \"\u7537\" &amp;&amp; $age &gt;= 16) {\n  echo \"\u60a8\u5df2\u8fbe\u5230\u9a7e\u9a76\u5e74\u9f84\";\n} else {\n  echo \"\u60a8\u672a\u6210\u5e74\";\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0c\u5916\u5c42 if \u8bed\u53e5\u68c0\u67e5\u5e74\u9f84\u662f\u5426\u5927\u4e8e\u6216\u7b49\u4e8e 18 \u5c81\u3002\u5982\u679c\u662f\uff0c\u5219\u8f93\u51fa &#8220;\u60a8\u5df2\u6210\u5e74&#8221;\u3002\u5982\u679c\u4e0d\u662f\uff0c\u5219\u68c0\u67e5\u6027\u522b\u662f\u5426\u4e3a &#8220;\u7537&#8221; \u4e14\u5e74\u9f84\u662f\u5426\u5927\u4e8e\u6216\u7b49\u4e8e 16 \u5c81\u3002\u5982\u679c\u662f\uff0c\u5219\u8f93\u51fa &#8220;\u60a8\u5df2\u8fbe\u5230\u9a7e\u9a76\u5e74\u9f84&#8221;\uff1b\u5426\u5219\uff0c\u8f93\u51fa &#8220;\u60a8\u672a\u6210\u5e74&#8221;\u3002<\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6761\u4ef6\u5fc5\u987b\u662f\u4e00\u4e2a\u5e03\u5c14\u8868\u8fbe\u5f0f\u6216\u53d8\u91cf\u3002<\/li>\n<li>\u4ee3\u7801\u5757\u53ef\u4ee5\u5305\u542b\u4efb\u610f\u6570\u91cf\u7684\u8bed\u53e5\u3002<\/li>\n<li>\u53ef\u4ee5\u5728 if \u8bed\u53e5\u540e\u9762\u4f7f\u7528 else \u6216 else if \u8bed\u53e5\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fphp\u4e2dif\u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5\u662f\u4ec0\u4e48\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>php if \u51fd\u6570\u7528\u4e8e\u6267\u884c\u6761\u4ef6\u8bed\u53e5\uff0c\u68c0\u67e5\u6761\u4ef6\u662f\u5426\u4e3a\u771f\u3002\u8bed\u6cd5\uff1aif (condition) { \u8981\u6267\u884c\u7684\u4ee3\u7801\u5757}\u3002\u53c2\u6570\uff1acondition\uff08\u6761\u4ef6\uff09\u3002\u8fd4\u56de\u503c\uff1a\u771f\u6216\u5047\u3002\u5d4c\u5957 if \u8bed\u53e5\u53ef\u7528\u4e8e\u521b\u5efa\u66f4\u590d\u6742\u7684\u6761\u4ef6\u3002 PHP if \u51fd\u6570\u7684\u4f7f\u7528\u65b9\u6cd5 if \u51fd\u6570\u5728 PHP \u4e2d\u7528\u4e8e\u6267\u884c\u6761\u4ef6\u8bed\u53e5\u3002\u5b83\u68c0\u67e5\u4e00\u4e2a\u6761\u4ef6\u662f\u5426\u4e3a true\uff0c\u5982\u679c\u4e3a true\uff0c\u5219\u6267\u884c\u6307\u5b9a\u4ee3\u7801\u5757\u3002 \u8bed\u6cd5\uff1a if (condition) { \/\/ \u8981\u6267\u884c\u7684\u4ee3\u7801\u5757 } \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b condition\uff1a\u8981\u8bc4\u4f30\u7684\u6761\u4ef6\u3002\u5b83\u53ef\u4ee5\u662f\u4efb\u4f55\u5e03\u5c14\u8868\u8fbe\u5f0f\u6216\u53d8\u91cf\u3002 \u8fd4\u56de\u503c\uff1a if \u51fd\u6570\u8fd4\u56de true \u6216 false\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u6761\u4ef6\u662f\u5426\u4e3a true\u3002 \u4f7f\u7528\u793a\u4f8b\uff1a $age = 18; if ($age &gt;= 18) { echo &#8220;\u60a8\u5df2\u6210\u5e74&#8221;; } else { echo &#8220;\u60a8\u672a\u6210\u5e74&#8221;; } \u767b\u5f55\u540e\u590d\u5236 \u5728\u4e0a\u9762\u7684\u793a\u4f8b\u4e2d\uff0cif \u51fd\u6570\u4f1a\u68c0\u67e5\u5e74\u9f84\u662f\u5426\u5927\u4e8e\u6216\u7b49\u4e8e [&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-27501","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27501","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=27501"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27501\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27501"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27501"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27501"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}