Home > Article > Backend Development > PHP&MySQL (2) - Even if you are sleepy, you have to read books
madan, everything dares to rush together. . . From now on, I will learn to drive at noon every day. I am so happy. . I feel very sleepy at night, but I still have to read books when I am sleepy. . . . . . . .
2. PHP scripting programming language
What variables and data types? I won’t record the very basic ones. Let’s talk about some things that are easy to ignore.
<?<span>php </span><span>define</span>("PI", 3.1415926); <span>//</span><span>常量的定义</span><span>echo</span> "圆周率=".<span>PI</span>."<br/>"; <span>//</span><span>.的链接作用,同样用于$var的赋值等</span><span>if</span> (<span>PI</span><3&&<span>PI</span>>=2<span>) { </span><span>$var</span>="shit"<span>; }</span><span>else</span><span>{ </span><span>echo</span> "f**k"."<hr/>"<span>; } </span><span>//</span><span> 先判断PI<3,如果不成立,就直接进入else——称为短路设计,加快程序速度; // 同理,为了实现程序的高效,把最容易出错的放前面,最复杂的计算放右边</span><span>$var</span>="asldkjflajdfklj"<span>; </span><span>$v2</span>=(<span>boolean</span>)<span>$var</span>; <span>//</span><span>强制类型转换</span><span>echo</span><span>$v2</span>;<span>echo</span> "<br/>"<span>; </span><span>$v_true</span>=<span>true</span>; <span>//</span><span>boolean值也可以直接赋值</span><span>if</span> (<span>is_bool</span>(<span>$v2</span>)&&<span>$v2</span>===<span>$v_true</span>) { <span>//</span><span>恒等===,可以判断数据类型是否相同;is_bool</span><span>echo</span> "Variables have the same value and type!"<span>; </span><span>echo</span> "<hr/>"<span>; } </span><span>//</span><span>另外,非恒等仍然是!==</span><span>$lll</span>="dfa"+333<span>; </span><span>var_dump</span>(<span>$lll</span>);<span>echo</span> "<hr/>"<span>; </span><span>print_r</span>(<span>$lll</span>);<span>echo</span> "<hr/>"<span>; </span><span>echo</span><span>gettype</span>(<span>$lll</span>);<span>echo</span> "<hr/>"<span>; </span><span>//</span><span>var_dump允许一次检查多个变量,同时提供信息;print_r多用来对数组和对象进行输出;</span><span>if</span> (<span>isset</span>(<span>$lll</span>)&&!<span>empty</span>(<span>$v2</span>)) { <span>//</span><span>判断是否为空</span><span>unset</span>(<span>$lll</span><span>); } </span><span>var_dump</span>(<span>$lll</span>);<span>echo</span> "<hr/>"; <span>//</span><span>会报错,但仍能输出null</span><span>function</span> doubleint(<span>$var</span>){ <span>//</span><span>自定义函数</span><span>if</span> (<span>is_int</span>(<span>$var</span><span>)) { </span><span>$var</span>=<span>$var</span>*2<span>; </span><span>return</span><span>$var</span><span>; }</span><span>else</span><span>{ </span><span>echo</span> "Please enter a int data."<span>; } } </span><span>echo</span> doubleint(<span>$var</span>);<span>echo</span> "<hr/>"<span>; </span><span>echo</span> doubleint(4);<span>echo</span> "<hr/>"<span>; </span><span>//</span><span>个人觉得,还是少用global和地址传递,逻辑上容易出错,程序没错,结果却不对 // 关于include和require // 多用include吧 // include失败了只是警告,后者则是错误然后中断程序 // 同时推荐没事儿就写绝对路径,好读也不易出错</span></span>
Everything to say is above, in summary: constants, connectors, custom functions, type conversion, type judgment, file references, identity symbols, short-circuit design, var_dump.
It’s rather messy.
Let’s take a final example, make your own multiplication table
<?<span>php </span><span>//</span><span>Chapter 2's example which is a chengfabiao</span><span>function</span> chengfabiao(<span>$var</span><span>){ </span><span>for</span> (<span>$row</span>=1;<span>$row</span><=<span>$var</span>;<span>$row</span>++<span>){ </span><span>for</span>(<span>$queue</span>=1;<span>$queue</span><=<span>$var</span>;<span>$queue</span>++<span>){ </span><span>$answer</span>=<span>$row</span>*<span>$queue</span><span>; </span><span>echo</span> "<span>$row</span>*<span>$queue</span>=".<span>$answer</span>." "<span>; } </span><span>echo</span> "<hr/>"<span>; } } </span><span>$var</span>=9<span>; chengfabiao(</span><span>$var</span>);
Choose it for yourself. You have to take out basic things and review them from time to time, or so I think.
The above has introduced PHP&MySQL (2) - even if you are sleepy, you have to read the book, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.