电路基础知识点总结 PHP新手总结的PHP基础知识
PHP新手总结的PHP基础知识
看了些PHP的基础知识 自己在这里总结下
在HTML嵌入PHP脚本有三种办法
<scriptlanguage= php > //嵌入方式一 echo( test ); </script>

<? //嵌入方式二 echo <br>test ; ?>
<?php //嵌入方式三 echo <br>test ; ?>
还有一种嵌入方式 即使用和Asp相同的标记<%%> 但要修改PHP ini 相关配置 不推荐使用
PHP注释分单行和多行注释 和java注释方式相同
<? //这里是单行注释 echo test ; ?>
注意不要有嵌套注释 如/*aaaaasdfasdfas*/ 这样的注释会出现问题
PHP主要的数据类型有 种 integer double string array object
函数内调用函数外部变量 需要先用global进行声明 否则无法访问 这是PHP与其他程序语言的一个区别 事例代码
<? $a= ; functiontest(){ echo$a; } test();//这里将不能输出结果
functiontest (){ global$a; echo$a; } test ();//这样可以输出结果 ?>
注意 PHP可以在函数内部声明静态变量 用途同C语言中
变量的变量 变量的函数
<? //变量的变量 $a= hello ; $$a= world ; echo $a$hello ;//将输出 helloworld echo $a${$a} ;//同样将输出 helloworld ?>
<? //变量的函数
functionfunc_ (){ print( test ); }
functionfun($callback){ $callback(); }
fun( func_ );//这样将输出 test ?>
PHP同时支持标量数组和关联数组 可以使用list()和array()来创建数组 数组下标从 开始 如
<? $a[ ]= abc ; $a[ ]= def ; $b[ foo ]= ;
$a[]= hello ;//$a[ ]= hello $a[]= world ;//$a[ ]= world
$name[]= jill ;//$name[ ]= jill $name[]= jack ;//$name[ ]= jack ?>
关联参数传递(&的使用) 两种方法 例
<? //方法一 functionfoo(&$bar){ $bar = andsomethingextra ; } $str= ThisisaString ; foo($str); echo$str;//output:ThisisaString andsomethingextra
echo <br> ; //方法二 functionfoo ($bar){ $bar = andsomethingextra ; } $str= ThisisaString ;
foo ($str); echo$str;//output:ThisisaString
echo <br> ;
foo (&$str); echo$str;//output:ThisisaString andsomethingextra ?>
函数默认值 PHP中函数支持设定默认值 与C++风格相同
<? functionmakecoffee($type= coffee ){ echo makingacupof$type n ; } echomakecoffee();// makingacupofcoffee echomakecoffee( espresso );// makingacupofespresso
functiontest($type= test $ff){//错误示例 return$type $ff; }
PHP的几个特殊符号意义
$变量 &变量的地址(加在变量前) @不显示错误信息(加在变量前) >类的方法或者属性 =>数组的元素值 ?:三元运算子
include()语句与require()语句
如果要根据条件或循环包含文件 需要使用include()
require()语句只是被简单的包含一次 任何的条件语句或循环等对其无效
由于include()是一个特殊的语句结构 因此若语句在一个语句块中 则必须把他包含在一个语句块中
<? //下面为错误语句 if($condition) include($file); else include($other);
lishixinzhi/Article/program/PHP/201311/21443