PHP&MySQL(二)——困也得啃书

WBOY
发布: 2016-07-29 09:01:01
原创
809 人浏览过

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>PI>=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<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>
登录后复制

要说的都在上面了,总结下就是:常量,连接符,自定义函数,类型转换,类型判断,文件引用,恒等符,短路设计,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>$var;<span>$row</span>++<span>){
        </span><span>for</span>(<span>$queue</span>=1;<span>$queue</span>$var;<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>);
登录后复制


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

以上就介绍了PHP&MySQL(二)——困也得啃书,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

相关标签:
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板