Maison > php教程 > php手册 > PHP&MySQL(二)困也得啃书,php教程

PHP&MySQL(二)困也得啃书,php教程

WBOY
Libérer: 2016-06-13 08:45:24
original
1391 Les gens l'ont consulté

PHP&MySQL(二)——困也得啃书,php教程

madan,所有事情都敢赶在一起。。。以后每天中午去学车啊,好开心。。晚上好困,但是困也得啃书。。。。。。。。

二、PHP脚本编程语言

什么变量啊,数据类型啊,特别特别基本的不记录了,说点容易忽略的。

<?<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&mdash;&mdash;称为短路设计,加快程序速度;
// 同理,为了实现程序的高效,把最容易出错的放前面,最复杂的计算放右边</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>
Copier après la connexion

要说的都在上面了,总结下就是:常量,连接符,自定义函数,类型转换,类型判断,文件引用,恒等符,短路设计,var_dump。

比较乱。

最后举个例子吧,自制乘法表

<?<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>);
Copier après la connexion


自己改着玩吧。基础的东西也得常常拿出来温习下,我是这么认为的。

 

Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Recommandations populaires
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal