详解php运行环境配置php.ini配置及php基础讲解1、PHP变量及数据类型1)$variable,变量以字母、_开始,不能有空格2)赋值$variable=value;3)弱类型,直接赋值,不需要显示声明数据类型4)基本数据类型:Integer,Double,String,Boolean,Object(对象或类),Array(数组)PHP片段四种表示形式。标准tags:shorttags:?>需要在php.ini中设置short_open_tag=on,默认是onasptags:<%%>需要在php.ini中设置asp_tags=on,默认是offscripttags:
5)特殊数据类型:Resourse(对第三方资源(如数据库)的引用),Null(空,未初始化的变量)3、操作符1)赋值操作符:=2)算术操作符:+,-,*,/,%(取模)3)连接操作符:.,无论操作数是什么,都当成String,结果返回String4)CombinedAssignmentOperators合计赋值操作符:+=,*=,/=,-=,%=,.=5)AutomaticallyIncrementingandDecrementing自动增减操作符:(1)++$variable,-$variable,先++或-,再做其他操作(2)$variable+=1<=>$variable++;$variable-=1<=>$variable-,跟c语言一样,先做其他操作,后++或-6)比较操作符:==(左边等于右边),!=(左边不等于右边),===(左边等于右边,且数据类型相同),>=,>,<,<=7)逻辑操作符:||óor,&&óand,xor(当左右两边有且只有一个是true,返回true),!4、注释:单行注释://,#多行注释:/**/5、每个语句以;号结尾,与java相同6、定义常量:define(“CONSTANS_NAME”,value)7、打印语句:print,与c语言相同8、流程控制语句1)if语句:(1)if(expression){//codetoexcuteifexpressionevaluatestotrue}(2)if(expression){}else{}(3)if(expression1){}elseif(expression2){}else{}2)swich语句switch(expression){caseresult//executethisifexpressionresultsinresult1break;caseresult//executethisifexpressionresultsinresult2break;default://executethisifnobreakstatement//hasbeenencounteredhitherto}3)?操作符:(expression)?returned_if_expression_is_true:returned_if_expression_is_false;4)while语句:(1)while(expression){//dosomething}(2)do{//codetobeexecuted}while(expression);5)for语句:for(initializationexpression;testexpression;modificationexpression){//codetobeexecuted}6)break;continue9、编写函数1)定义函数:functionfunction_name($argument1,$argument2,……)//形参{//functioncodehere;}2)函数调用function_name($argument1,$argument2,……);//形参3)动态函数调用(DynamicFunctionCalls):Listing6.5";}$function_holder="sayHello";//将函数名赋值给变量$function_holder$function_holder();//变量$function_holder成为函数sayHello的引用,调用$function_holder()相当于调用sayHello?>4)变量作用域:全局变量:Listing6.8";}meaningOfLife();?>5)使用staticListing6.10$num_of_calls.$txt";}numberedHeading("Widgets");//第一次调用时,打印$num_of_calls值为1print("Webuildafinerangeofwidgets");numberedHeading("Doodads");/*第一次调用时,打印$num_of_calls值为2,因为变量是static型的,static型是常驻内存的*/print("Finestintheworld
");?>6)传值(value)和传址(reference):传值:functionfunction_name($argument)
Listing6.13