恋鱼随风

=。= 全球唯一指定“最”官方域名http://www.lianyusuifeng.com
Jan 26

PHP基础知识 夜晚

Posted by 恋鱼随风 at 04:02 | 网络时代 | 阅读(682) | 转自 本站原创
看了些PHP的基础知识,自己在这里总结下:

1,在HTML嵌入PHP脚本有三种办法:

<script language="php">
//嵌入方式一
echo("test");
</script>
<?
//嵌入方式二
echo "<br>test2";
?>
<?php
//嵌入方式三
echo "<br>test3";
?>
  还有一种嵌入方式,即使用和Asp相同的标记<%%>,但要修改PHP.ini 相关配置,不推荐使用。

2,PHP注释分单行和多行注释,和java注释方式相同。

<?
//这里是单行注释
echo "test";
/*
这里是多行注释!可以写很多行注释内容
*/
?>
  注意不要有嵌套注释,如/*aaaa/*asdfa*/asdfasdfas*/,这样的注释会出现问题。

3,PHP主要的数据类型有5种:

integer,double,string,array,object。
4,函数内调用函数外部变量,需要先用global进行声明,否则无法访问,这是PHP与其他程序语言的一个区别。事例代码:

<?
$a=1;
function test(){
echo $a;
}
test();    //这里将不能输出结果“1”。
function test2(){
    global $a;
    echo $a;
}
test2();    //这样可以输出结果“1”。
?>
  注意:PHP可以在函数内部声明静态变量。用途同C语言中。

5,变量的变量,变量的函数

<?
//变量的变量
$a="hello";
$$a="world";
echo "$a $hello";    //将输出"hello world"
echo "$a ${$a}";    //同样将输出"hello world"
?>
<?
//变量的函数
function func_1(){
  print("test");
}
function fun($callback){
  $callback();
}
fun("func_1");    //这样将输出"test"
内文分页: [1] [2]
Tags: , ,
发表评论
表情
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
emotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]