菜鸟学习 动态网页PHP基本学习笔记
发布时间:2022-03-02 18:25:57 所属栏目:PHP教程 来源:互联网
导读:1、 PHP片段四种表示形式。 标准tags:?php ? short tags:? ? 需要在php.ini中设置short _open_tag=on,默认是on asp tags: % %需要在php.ini中设置asp_tags=on,默认是off script tags:script language=php/script 2、 PHP变量及数据类型 1)$variable
1、 PHP片段四种表示形式。 标准tags:<?php ?> short tags:<? ?> 需要在php.ini中设置short _open_tag=on,默认是on asp tags: <% %>需要在php.ini中设置asp_tags=on,默认是off script tags:<script language=”php”></script> 2、 PHP变量及数据类型 1)$variable ,变量以字母、_开始,不能有空格 2)赋值$variable=value; 3)弱类型,直接赋值,不需要显示声明数据类型 3、 操作符 1)赋值操作符:= 2)算术操作符: ,-,*,/,%(取模) 3)连接操作符:. ,无论操作数是什么,都当成String,结果返回String 4)Combined Assignment Operators合计赋值操作符: =,*=,/=,-=,%=,.= 5)Automatically Incrementing and Decrementing自动增减操作符: (1)$variable =1 <=>$variable ;$variable-=1 <=>$variable-,跟c语言一样,先做其他操作,后 或- (2) $variable,-$variable,先 或-,再做其他操作 6)比较操作符:= =(左边等于右边),!=(左边不等于右边),= = =(左边等于右边,且数据类型相同),>=,>,<,<= 7)逻辑操作符:|| ó or,&&óand,xor(当左右两边有且只有一个是true,返回true),! 4、 注释: 单行注释:// ,# 多行注释:/* */ 5、 每个语句以;号结尾,与java相同 6、 定义常量:define(“CONSTANS_NAME”,value) 7、 打印语句:print,与c语言相同 8、 流程控制语句 1)if语句: (1)if(expression) { } else { } 2)swich语句 switch ( expression ) { case result1: // execute this if expression results in result1 break; case result2: // execute this if expression results in result2 break; default: // execute this if no break statement // has been encountered hitherto } 3)?操作符: ( expression )?returned_if_expression_is_true:returned_if_expression_is_false; 4)while语句: (1) while ( expression ) { // do something } (2)do { // code to be executed } while ( expression ); 5)for语句: for ( initialization expression; test expression; modification expression ) { // code to be executed } 6)break;continue 9、 编写函数 1)定义函数: function function_name($argument1,$argument2,……) //形参 { //function code here; } 2)函数调用 function_name($argument1,$argument2,……); //形参 3)动态函数调用(Dynamic Function Calls): 1: <html> 2: <head> 3: <title>Listing 6.5</title> 4: </head> 5: <body> 6: <?php 7: function sayHello() { //定义函数sayHello 8: print "hello<br>"; 9: } 10: $function_holder = "sayHello"; //将函数名赋值给变量$function_holder (编辑:PHP编程网 - 黄冈站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |