{"id":1255,"date":"2021-05-26T18:03:09","date_gmt":"2021-05-26T10:03:09","guid":{"rendered":"http:\/\/www.zyhcoding.club\/?p=1255"},"modified":"2021-05-26T20:21:14","modified_gmt":"2021-05-26T12:21:14","slug":"php%e5%9f%ba%e7%a1%80","status":"publish","type":"post","link":"http:\/\/www.zyhcoding.club\/index.php\/2021\/05\/26\/php%e5%9f%ba%e7%a1%80\/","title":{"rendered":"PHP\u57fa\u7840"},"content":{"rendered":"<h4>PHP<\/h4>\n<p>PHP\u662f\u4e00\u79cd\u521b\u5efa\u52a8\u6001\u4ea4\u4e92\u6027\u7ad9\u70b9\u7684\u5f3a\u6709\u529b\u7684\u670d\u52a1\u5668\u7aef\u811a\u672c\u8bed\u8a00\uff0c\u5168\u79f0<code>Hypertext Preprocessor<\/code>(\u8d85\u6587\u672c\u9884\u5904\u7406\u5668)\u3002<\/p>\n<p>PHP\u53ef\u514d\u8d39\u4e0b\u8f7d\u4f7f\u7528\uff0cPHP\u4ee3\u7801\u5728\u670d\u52a1\u5668\u4e0a\u6267\u884c\uff0c\u7ed3\u679c\u4ee5\u7eafHTML\u5f62\u5f0f\u8fd4\u56de\u7ed9\u6d4f\u89c8\u5668\u3002PHP\u6587\u4ef6\u540e\u7f00\u662f<code>.php<\/code>\u3002<\/p>\n<p>PHP\u662f\u670d\u52a1\u5668\u7aef\u811a\u672c\uff0c\u5fc5\u987b\u653e\u5728WAMP\u7684www\u76ee\u5f55\u4e0b\u9762\uff0c\u6d4f\u89c8\u5668\u8f93\u5165<code>localhost\/filename.php<\/code>\u624d\u80fd\u6253\u5f00\u3002<\/p>\n<h4>PHP \u57fa\u672c\u8bed\u6cd5<\/h4>\n<p>PHP\u811a\u672c\u53ef\u4ee5\u653e\u5728\u6587\u6863\u4e2d\u7684\u4efb\u4f55\u4f4d\u7f6e\uff0c\u4ee3\u7801\u653e\u5728<code>&lt;?php  ?&gt;<\/code>\u91cc\u9762\u3002PHP\u6587\u4ef6\u901a\u5e38\u662f\u4e00\u4e9bHTML\u6807\u7b7e\u548cPHP\u811a\u672c\u4ee3\u7801\uff0c\u4ee3\u7801\u6267\u884c\u987a\u5e8f\u4e5f\u662f\u4ece\u4e0a\u5230\u4e0b\uff0c\u4e0b\u5217\u4ee3\u7801\u8f93\u51fa<code>Hello World!<\/code>\u3002\u6ce8\u91ca\u8bed\u6cd5\u540cC++\u3002<\/p>\n<pre><code class=\"language-php\">&lt;!DOCTYPE html&gt;\n&lt;html&gt;\n&lt;body&gt;\n    &lt;h1&gt;My first PHP page&lt;\/h1&gt;\n\n&lt;?php\n    \/\/ \u5355\u884c\u6ce8\u91ca\n    echo &quot;Hello World!&quot;;\n\n?&gt;\n\n&lt;\/body&gt;\n&lt;\/html&gt;<\/code><\/pre>\n<h4>PHP \u53d8\u91cf<\/h4>\n<p>PHP\u662f\u5f31\u53d8\u91cf\u8bed\u8a00\uff0c\u4e0d\u9700\u8981\u58f0\u660e\u53d8\u91cf\u7c7b\u578b\uff0c\u53d8\u91cf\u540d\u5b57\u4ee5<code>$<\/code>\u7b26\u53f7\u5f00\u59cb\uff0c\u540e\u9762\u8ddf\u53d8\u91cf\u7684\u540d\u79f0\u3002\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>var<\/code>\u5173\u952e\u5b57\u58f0\u660e\u4e00\u4e2a\u53d8\u91cf\u3002<br \/>\n\u4e3b\u8981\u7c7b\u578b\u6709\uff1a\u5b57\u7b26\u4e32\uff0c\u6574\u6570\uff0c\u6d6e\u70b9\u6570\uff0c\u5e03\u5c14\u578b\uff0c\u6570\u7ec4\uff0c\u5bf9\u8c61\uff0cPHP NULL\u503c\u3002<\/p>\n<pre><code class=\"language-php\">&lt;?php\n$x=5;\n$y=6;\n$z=$x+$y;\necho $z;\n\n$cars=array(&quot;Volvo&quot;,&quot;BMW&quot;,&quot;Toyota&quot;);\n\n\/\/ \u5b9a\u4e49\u7c7b\u4ee5\u53ca\u5b9e\u73b0\u5176\u6784\u9020\u51fd\u6570\u548c\u5176\u5b83\u65b9\u6cd5\u3002\nclass Car\n{\n  var $color;\n  function __construct($color=&quot;green&quot;) {\n    $this-&gt;color = $color;\n  }\n  function what_color() {\n    return $this-&gt;color;\n  }\n}\n\n?&gt;<\/code><\/pre>\n<p>\u53d8\u91cf\u67094\u79cd\u4e0d\u540c\u7684\u53d8\u91cf\u4f5c\u7528\u57df\uff1a<code>local global static parameter<\/code>\uff0c<code>global<\/code>\u8868\u793a\u5168\u5c40\uff0c<code>static<\/code>\u8868\u793a\u9759\u6001\u3002<\/p>\n<h4>PHP \u8f93\u51fa<\/h4>\n<p>PHP\u6709\u4e24\u4e2a\u57fa\u672c\u7684\u8f93\u51fa\u65b9\u5f0f\uff1a<code>print echo<\/code><br \/>\n<code>echo<\/code>-\u53ef\u4ee5\u8f93\u51fa\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u4e32<br \/>\n<code>print<\/code>-\u53ea\u5141\u8bb8\u8f93\u51fa1\u4e2a\u5b57\u7b26\u4e32\uff0c\u51fd\u6570\u8fd4\u56de\u4e3a1<\/p>\n<p><code>echo<\/code>\u662f\u4e00\u4e2a\u8bed\u8a00\u7ed3\u6784\uff0c\u8f93\u51fa\u591a\u4e2a\u5b57\u7b26\u4e32\u65f6\uff0c\u7528\u9017\u53f7\u9694\u5f00\u5b57\u7b26\u4e32\u3002<\/p>\n<pre><code class=\"language-php\">&lt;?php\necho &quot;&lt;h2&gt;PHP \u5f88\u6709\u8da3!&lt;\/h2&gt;&quot;;\necho &quot;Hello world!&lt;br&gt;&quot;;\necho &quot;\u6211\u8981\u5b66 PHP!&lt;br&gt;&quot;;\necho &quot;\u8fd9\u662f\u4e00\u4e2a&quot;, &quot;\u5b57\u7b26\u4e32\uff0c&quot;, &quot;\u4f7f\u7528\u4e86&quot;, &quot;\u591a\u4e2a&quot;, &quot;\u53c2\u6570\u3002&quot;;\n?&gt;<\/code><\/pre>\n<h4>PHP \u7c7b\u578b\u6bd4\u8f83<\/h4>\n<p>PHP\u662f\u5f31\u7c7b\u578b\u8bed\u8a00\uff0c\u5bf9PHP\u53d8\u91cf\u7684\u6bd4\u8f83\u5305\u542b\u677e\u6563\u6bd4\u8f83\u548c\u4e25\u683c\u6bd4\u8f83\u3002<br \/>\n\u677e\u6563\u6bd4\u8f83\uff1a<code>==<\/code>\uff0c\u53ea\u6bd4\u8f83\u503c\uff0c\u4e0d\u6bd4\u8f83\u7c7b\u578b\u3002<br \/>\n\u4e25\u683c\u6bd4\u8f83\uff1a<code>===<\/code>\uff0c\u9664\u4e86\u6bd4\u8f83\u503c\uff0c\u8fd8\u8981\u6bd4\u8f83\u7c7b\u578b\u3002<\/p>\n<pre><code class=\"language-php\">&lt;?php\nif (42 == &quot;42&quot;) {\n    echo &quot;\u503c\u76f8\u7b49&quot;;\n}\n\necho PHP_EOL;\/\/\u6362\u884c\u7b26\n\necho (42===&quot;42&quot;);\n\n?&gt;\n<\/code><\/pre>\n<h4>PHP \u5e38\u91cf<\/h4>\n<p>\u4e0d\u540c\u4e8e\u522b\u7684\u7f16\u7a0b\u8bed\u8a00\uff0cPHP\u58f0\u660e\u5e38\u91cf\u9700\u8981\u7528\u5230<code>define(string $name, mixed $value [, bool $case_insentive=false])<\/code>\u51fd\u6570\u3002\u5e38\u91cf\u9ed8\u8ba4\u662f\u5168\u5c40\u7684\u3002<br \/>\n\u51fd\u6570\u5404\u53c2\u6570\u529f\u80fd\uff1a<br \/>\n<code>$name<\/code>-\u9700\u8981\u5b9a\u4e49\u7684\u5e38\u91cf\u7684\u540d\u79f0<br \/>\n<code>$value<\/code>-\u53d8\u91cf\u503c<br \/>\n<code>case_insentive<\/code>-\u53ef\u7f3a\u7701\u53c2\u6570\uff0c\u8868\u793a\u8be5\u53d8\u91cf\u540d\u79f0\u5927\u5c0f\u5199\u662f\u5426\u654f\u611f\uff0c\u9ed8\u8ba4\u4e3afalse\u4e0d\u660e\u663e\u3002<\/p>\n<pre><code class=\"language-php\">&lt;?php\ndefine(&quot;GREETING&quot;, &quot;welcome!&quot;);\necho GREETING;\n?&gt;<\/code><\/pre>\n<h4>PHP \u5b57\u7b26\u4e32<\/h4>\n<p>\u5b57\u7b26\u4e32\u53d8\u91cf\u7528\u4e8e\u5305\u542b\u6709\u5b57\u7b26\u7684\u503c\u3002<br \/>\n<code>$a.$b<\/code>-<code>.<\/code>\u662f\u5e76\u7f6e\u8fd0\u7b97\u7b26\uff0c\u7528\u4e8e\u8fde\u63a5\u4e24\u4e2a\u5b57\u7b26\u4e32\u3002<br \/>\n<code>strlen($a)<\/code>-\u8fd4\u56de\u5b57\u7b26\u4e32\u7684\u957f\u5ea6\u3002\u4e0b\u6807\u4ece0\u5f00\u59cb\u3002<br \/>\n<code>strpos($a, $b)<\/code>-\u5728a\u4e2d\u5339\u914d\u662f\u5426\u5b58\u5728b\uff0c\u4e0d\u5b58\u5728\u8fd4\u56deFALSE,\u5b58\u5728\u8fd4\u56de\u7b2c\u4e00\u6b21\u51fa\u73b0\u7684\u4f4d\u7f6e\u3002<\/p>\n<pre><code class=\"language-php\">&lt;?php\n$a = &quot;hello world!&quot;;\n$b = &quot;world&quot;;\nprint $a.$b;\n\nprint strlen($a.$b);\n\necho ($a.$b)[0];\n\necho strpos($a, $b);\n?&gt;<\/code><\/pre>\n<h4>PHP\u6570\u7ec4<\/h4>\n<p>PHP\u4e2d\u4f7f\u7528<code>array()<\/code>\u51fd\u6570\u521b\u5efa\u6570\u7ec4\uff0c\u67093\u79cd\u7c7b\u578b\u6570\u7ec4\uff1a<strong>\u6570\u503c\u6570\u7ec4\uff0c\u5173\u8054\u6570\u7ec4\uff0c\u591a\u7ef4\u6570\u7ec4<\/strong>\u3002<code>count($arr)<\/code>\u51fd\u6570\u8fd4\u56de\u6570\u7ec4\u7684\u957f\u5ea6\u3002<br \/>\n\u6570\u503c\u6570\u7ec4\u5c31\u662f\u666e\u901a\u6570\u7ec4\u3002\u3002<\/p>\n<pre><code class=\"language-php\">$cars=array(&quot;Volvo&quot;,&quot;BMW&quot;,&quot;Toyota&quot;);\necho count($cars);<\/code><\/pre>\n<p>\u5173\u8054\u6570\u7ec4\u7c7b\u4f3c\u4e8e<code>map<\/code>\uff0c\u5373\u952e-\u503c\u6570\u7ec4\u3002\u4f7f\u7528\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-php\">$age=array(&quot;Peter&quot;=&gt;&quot;35&quot;,&quot;Ben&quot;=&gt;&quot;37&quot;,&quot;Joe&quot;=&gt;&quot;43&quot;);\n$age[&#039;hello&#039;]=&quot;world!&quot;\uff1b\n\nfor ($age as $x=&gt;$x_value) {\n    echo &quot;key = &quot;.$x.&quot;, value = &quot;.$x_value;\n}\n<\/code><\/pre>\n<h4>PHP \u51fd\u6570<\/h4>\n<p>\u521b\u5efa\u51fd\u6570<\/p>\n<pre><code class=\"language-php\">&lt;php\nfunction myfunction() {\n    \/\/ \u8981\u6267\u884c\u7684\u4ee3\u7801\n    return $x;    \/\/ x\u53ef\u4ee5\u662f\u4efb\u4f55\u7c7b\u578b\n}\n\nmyfunction();\n\n?&gt;<\/code><\/pre>\n<h4>PHP\u9762\u5411\u5bf9\u8c61<\/h4>\n","protected":false},"excerpt":{"rendered":"<p>PHP PHP\u662f\u4e00\u79cd\u521b\u5efa\u52a8\u6001\u4ea4\u4e92\u6027\u7ad9\u70b9\u7684\u5f3a\u6709\u529b\u7684\u670d\u52a1\u5668\u7aef\u811a\u672c\u8bed\u8a00\uff0c\u5168\u79f0Hypertext Prepr [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[72],"tags":[],"_links":{"self":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1255"}],"collection":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/comments?post=1255"}],"version-history":[{"count":13,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1255\/revisions"}],"predecessor-version":[{"id":1270,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/posts\/1255\/revisions\/1270"}],"wp:attachment":[{"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/media?parent=1255"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/categories?post=1255"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.zyhcoding.club\/index.php\/wp-json\/wp\/v2\/tags?post=1255"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}