PHP入门学习基础教程.docx
《PHP入门学习基础教程.docx》由会员分享,可在线阅读,更多相关《PHP入门学习基础教程.docx(17页珍藏版)》请在三一办公上搜索。
1、PHP入门学习基础教程、 PHP片段四种表示形式。标准tags:<?php ?>short tags:<? ?> 需要在php.ini中设置short _open_tag=on,默认是onasp tags: <% %>需要在php.ini中设置asp_tags=on,默认是offscript tags:<script language=”php”></script>2、 PHP变量及数据类型1) $variable ,变量以字母、_开始,不能有空格2) 赋值$variable=value;3) 弱类型,直接赋值,不需要显示声明数据类型4) 基本数据类型:
2、Integer,Double,String,Boolean,Object,Array(数组)5) 特殊数据类型:Resourse的引用),Null3、 操作符1) 赋值操作符:=2) 算术操作符:+,-,*,/,%3) 连接操作符:. ,无论操作数是什么,都当成String,结果返回String4) Combined Assignment Operators合计赋值操作符:+=,*=,/=,-=,%=,.=5) Automatically Incrementing and Decrementing自动增减操作符:$variable+=1 <=>$variable+;$variable-
3、=1 <=>$variable-,跟c语言一样,先做其他操作,后+或-+$variable,-$variable,先+或-,再做其他操作6) 比较操作符:= =,!=,= = =,>=,>,<,<=7) 逻辑操作符:| or,&and,xor(当左右两边有且只有一个是true,返回true),!4、 注释:单行注释:/ ,#多行注释:/* */5、 每个语句以;号结尾,与java相同6、 定义常量:define(“CONSTANS_NAME”,value)7、 打印语句:print,与c语言相同8、 流程控制语句1) if语句:if(expression)/code t
4、o excute if expression evaluates to trueif(expression)else(3)if(expression1)elseif(expression2)else2) swich语句switch ( expression )case result/ execute this if expression results in result1break;case result/ execute this if expression results in result2break;default:/ execute this if no break stateme
5、nt/ has been encountered hitherto3) ?操作符:( expression )?returned_if_expression_is_true:returned_if_expression_is_false;4) while语句: while ( expression ) / do somethingdo/ code to be executed while ( expression );5) for语句:for ( initialization expression; test expression; modification expression ) / co
6、de to be executed6) break;continue9、 编写函数1) 定义函数:function function_name($argument1,$argument2,) /形参/function code here;2) 函数调用function_name($argument1,$argument2,); /形参3) 动态函数调用:<html><head><title>Listing 6.5</title></head><body><?phpfunction sayHello /定义函数sayHelloprint hel
7、lo<br>$function_holder = sayHello; /将函数名赋值给变量$function_holder$function_holder; /变量$function_holder成为函数sayHello的引用,调用$function_holder相当于调用sayHello?></body></html>4) 变量作用域:全局变量:<html><head><title>Listing 6.8</title></head><body><?php$life=42;function meaningOfL
8、ife global $life;/*在此处重新声明$life为全局变量,在函数内部访问全局变量必须这样,如果在函数内改变变量的值,将在所有代码片段改变*/print The meaning of life is $life<br> meaningOfLife;?></body></html>5) 使用static<html><head><title>Listing 6.10</title></head><body><?phpfunction numberedHeading( $txt ) static $num
9、_of_calls = 0;$num_of_calls+;print <h1>$num_of_calls. $txt</h1>numberedHeading(Widgets); /第一次调用时,打印$num_of_calls值为1print(We build a fine range of widgets<p>);numberedHeading(Doodads); /*第一次调用时,打印$num_of_calls值为2,因为变量是static型的,static型是常驻内存的*/print(Finest in the world<p>);?></body
10、></html>6) 传值和传址:传值:function function_name($argument)<html><head><title>Listing 6.13</title></head><body><?phpfunction addFive( $num ) $num += 5;$orignum = 10;addFive( &$orignum );print( $orignum );?></body></html>结果:10传址:funciton function_name(&$argument)&l
11、thtml><head><title>Listing 6.14</title></head><body><?phpfunction addFive( &$num ) $num += 5; /*传递过来的是变量$num的引用,因此改变形参$num的值就是真正改变变量$orignum物理内存中保存的值*/$orignum = 10;addFive( $orignum );print( $orignum );?></body></html>结果:157) 创建匿名函数:create_function(string1,string2)
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- PHP 入门 学习 基础教程
链接地址:https://www.31ppt.com/p-3163764.html