🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
# 第十六课 php7+ 变量类型声明有两种模式。允许使用下列类型参数**int**,**string**,**float**,**bool** 同时不能再使用整型,字符串,浮点型,布尔作为类的名字了 ``` <pre class="calibre14">``` declare <span class="token2">(</span>strict_types <span class="token">=</span> <span class="token3">1</span><span class="token2">)</span><span class="token2">;</span> <span class="token5">function</span> <span class="token1">add</span><span class="token2">(</span>int $a<span class="token2">,</span> int $b<span class="token2">)</span><span class="token2">:</span> int <span class="token2">{</span> <span class="token5">return</span> $a<span class="token">+</span>$b<span class="token2">;</span> <span class="token2">}</span> ``` ``` ``` <pre class="calibre14">``` $a <span class="token">=</span>$_GET<span class="token2">[</span><span class="token4">'a'</span><span class="token2">]</span><span class="token">?</span><span class="token">?</span> <span class="token4">'none'</span><span class="token2">;</span> 等价于 <span class="token1">isset</span><span class="token2">(</span>$_GET<span class="token2">[</span><span class="token4">'a'</span><span class="token2">]</span><span class="token2">)</span><span class="token">?</span>$_GET<span class="token2">[</span><span class="token4">'a'</span><span class="token2">]</span><span class="token2">:</span><span class="token4">"none"</span> <span class="token1">define</span><span class="token2">(</span><span class="token4">'ARR'</span><span class="token2">,</span><span class="token2">[</span><span class="token4">'a'</span><span class="token2">,</span><span class="token4">'b'</span><span class="token2">]</span><span class="token2">)</span><span class="token2">;</span> 支持数组 $funcx <span class="token">=</span> <span class="token5">function</span><span class="token2">(</span>$x<span class="token2">)</span><span class="token2">{</span><span class="token5">return</span> <span class="token4">'function匿名函数'</span><span class="token2">.</span>$x<span class="token2">;</span><span class="token2">}</span><span class="token2">;</span> $HTTP_RAW_POST_DATA 变量被移除<span class="token2">,</span> 使用php<span class="token2">:</span><span class="token">/</span><span class="token">/</span>input来代 ``` ``` ``` <pre class="calibre16">``` <span class="token1">random_int</span><span class="token2">(</span><span class="token3">1000</span><span class="token2">,</span><span class="token3">9999</span><span class="token2">)</span><span class="token2">;</span> 随机数字 <span class="token3">7</span><span class="token">+</span> <span class="token1">bin2hex</span><span class="token2">(</span><span class="token1">random_bytes</span><span class="token2">(</span><span class="token3">2</span><span class="token2">)</span><span class="token2">)</span><span class="token2">;</span> 四位随机数<span class="token2">,</span><span class="token3">4</span>就是<span class="token3">8</span>位随机数 ``` ```