💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
# 第一课 流程控制和运算 > 流程控制,break终止 continue 跳过 ``` <pre class="calibre14">``` <span class="token5">if</span><span class="token2">(</span>expr<span class="token2">)</span><span class="token2">{</span> <span class="token2">}</span><span class="token1">elseif</span><span class="token2">(</span>expr<span class="token2">)</span><span class="token2">{</span> <span class="token2">}</span><span class="token5">else</span><span class="token2">{</span> <span class="token2">}</span> <span class="token1">switch</span><span class="token2">(</span>val<span class="token2">)</span><span class="token2">{</span> case v1<span class="token2">:</span> <span class="token5">break</span><span class="token2">;</span> default<span class="token2">:</span> <span class="token2">}</span> <span class="token5">while</span><span class="token2">(</span>expr<span class="token2">)</span><span class="token2">{</span> <span class="token2">}</span> <span class="token5">do</span><span class="token2">{</span> <span class="token2">}</span><span class="token5">while</span><span class="token2">(</span>expr<span class="token2">)</span> <span class="token5">for</span><span class="token2">(</span>expr1<span class="token2">;</span>expr2<span class="token2">;</span>expr3<span class="token2">)</span><span class="token2">{</span> <span class="token2">}</span> <span class="token1">foreach</span><span class="token2">(</span>$arr as $k<span class="token">=</span><span class="token">></span>$v<span class="token2">)</span><span class="token2">{</span> <span class="token2">}</span> ``` ``` > 特殊写法 endif endfor endwhile endswitch endforeach > 逻辑运算 || 或 && 与 ! 非 > 引用全局变量 ``` <pre class="calibre14">``` global $str<span class="token2">;</span> ``` ``` > 字符串定义 ``` <pre class="calibre14">``` $is <span class="token">=</span> <span class="token4">"ok"</span><span class="token2">;</span> $str <span class="token">=</span> <span class="token"><</span><span class="token"><</span><span class="token"><</span>EOF my name $is Jiang Qihui<span class="token">!</span> EOF<span class="token2">;</span> ``` ``` > 传值和传引用 ``` <pre class="calibre14">``` 按值传递:函数范围内对值的任何改变在函数外部都会被忽略 按引用传递:函数范围内对值的任何改变在函数外部也能反映出这些修改 优缺点:按值传递时,php必须复制值。特别是对于大型的字符串和对象来说,这将会是一个代价很大的操作。按引用传递则不需要复制值,对于性能提高很有好处。 ``` ``` > 控制错误@ ``` <pre class="calibre14">``` @<span class="token1">fn</span><span class="token2">(</span><span class="token2">)</span> ``` ``` > GET和POST区别 ``` <pre class="calibre14">``` get是发送请求HTTP协议通过url参数传递进行接收<span class="token2">,</span>而post是实体数据<span class="token2">,</span>可以通过表单提交大量信息<span class="token2">.</span> ``` ``` > session和cookie区别 ``` <pre class="calibre14">``` session<span class="token2">:</span>储存用户访问的全局唯一变量<span class="token2">,</span>存储在服务器上的php指定的目录中的(session_dir)的位置进行的存放 cookie<span class="token2">:</span>用来存储连续訪問一个頁面时所使用,是存储在客户端,对于Cookie来说是存储在用户WIN的Temp目录中的。 两者都可通过时间来设置时间长短 ``` ``` > echo(),print(),print\_r()区别 ``` <pre class="calibre14">``` echo是PHP语句<span class="token2">,</span> print和print_r是函数<span class="token2">,</span>语句没有返回值<span class="token2">,</span>函数可以有返回值 <span class="token1">print</span><span class="token2">(</span><span class="token2">)</span>只能打印出简单类型变量的值<span class="token2">(</span>如int<span class="token2">,</span>string<span class="token2">)</span> <span class="token1">print_r</span><span class="token2">(</span><span class="token2">)</span>可以打印出复杂类型变量的值<span class="token2">(</span>如数组<span class="token2">,</span>对象<span class="token2">)</span> echo 输出一个或者多个字符串 ``` ``` > 优化mysql ``` <pre class="calibre14">``` 选择正确数据类型<span class="token2">,</span>设置合适的字段长度 优化查询语句<span class="token2">,</span>事务处理<span class="token2">,</span>建立索引 使用左右连接替代子查询 ``` ``` > include和require,include\_once和require\_once ``` <pre class="calibre14">``` require 出现错误停止运行 include 出现错误继续运行 include_once和require_once 有重复不会出错<span class="token2">,</span>只处理一次 一般选用 require_once ``` ``` > 常见状态 ``` <pre class="calibre16">``` <span class="token3">200</span> 成功 <span class="token3">404</span>未找到 <span class="token3">301</span>跳转 <span class="token3">401</span>未授权 ``` ```