php文件可以写HTML,scc,以及js php代码必须写在phpphp标记中
标记的写法:
啊啊啊啊,好难啊";
?>
;">么么么额嗯嗯嘛
";//换行
$b = 5;
echo $a." ",$b;//10 5
//址的传递(引用赋值)
$a = 10;
$b = &$a;
echo $a;//10
echo " ";
echo $b;//10
$b = 5;
echo $a;//5
echo " ";
echo $b;//5
//变量的变量:可以直接将一个变量的值作为下一个变量的名
$a = "hello";
$hello = "world";
echo $$a;//world
$a = "hi";
$$a = "world";
echo $hi;//world
?>
";
print_r($_SERVER);
echo "
";
echo $_SERVER["SERVER_NAME"];//输出当前主机名
echo $_SERVER["HTTP_USER_AGENT"];//输出用户代理
echo ""; print_r($_GET); echo ""; echo '
'; print_r($_POST); echo ""; //$_REQUEST:获取get请求以及post请求方式的参数,但是安全性不高且缓慢,不推荐使用 echo "
"; print_r($_REQUEST); echo ""; //$_COOKIE:可以进行cookie的进行设置以及获取 $_COOKIE["username"] = "sita"; echo "
"; print_r($_COOKIE); echo ""; //$_SESSION:可以获取或设置存储在服务器端的会话储存 session_start();//开启session $_SESSION["username"] = "xxx"; $_SESSION["pwd"] = 123444; echo "
"; print_r($_SESSION); echo ""; $a = 10; $b = "hello world"; //$GLOBALS:获取本脚本中的全局变量 echo "
"; print_r($GLOBALS); echo ""; echo 0; //0 $c = "hi"; echo $GLOBALS['a'] == $a;//1 echo $GLOBALS['a'] != $a;//啥都没有 //$_FILES:获取所上传的文件 // 1.是html标签,意思是按原样输出不做更改。 2.php代码中用pre主要是做错误代码输出时候,或者打印数组输出起到保持格式的统一性。 ?>
";
echo PI;
define("PI",3.14);
//魔术常量:php预定义一些常量,由于使用的位置不一样得到的结果就会不一样,就称之为魔术常量
echo "
";
echo __DIR__;//获取当前访问文件的目录名
echo "
";
echo __FILE__;//获取当前访问文件的系统盘的文件名
echo "
";
echo __LINE__;//获取当前行的行号
function fn(){
echo __FUNCTION__;//获取当前函数的函数名
}
fn();
echo "
";
class myClss{
function show(){
echo __CLASS__;//获取当前的类的名字
echo "
";
echo __METHOD__;//获取当前的方法名
}
}
$obj = new myClss();//实例化一个对象
$obj -> show();//使用实例化对象的方法
?>
";
$a = 0xff;//十六进制数
echo $a;//255
echo gettype($a);//interge
$a = 0777;
echo $a;//511
echo gettype($a);//interge
echo "
";
$a = 0b1010;//二进制
echo $a;//10
echo gettype($a);//interge
//浮点型
echo "
";
$b = 1.482489;
echo gettype($b);//double
echo "
";
$b = 3e10;//3*10^10NNZ
echo gettype($b);//double
echo "
";
//字符串
$str = "hello world";
echo gettype($str);//string
echo "
";
var_dump($str);//输出任何类型的数据并显示改数据的类型
$str = "hi hi hi";
echo "
";
echo gettype($str);//string
echo "
";
$str = "\"\"";
echo $str;//""
echo gettype($str);//string
echo "
";
//定界符
$str = << ";
echo gettype($str);//string
$bol = true;
gettype($bol);//boolean
$bol = false;
gettype($bol);//boolean
//数组类型
echo "
";
$arr = [1,2,3,4];
$arr =["hello","world","today","happy"];
//关联数组:下标为字符串的数组
$arr["魔都"] = "上海";
$arr["首都"] = "北京";
$arr["雾都"] = "伦敦";
echo "
";
var_dump($arr);
echo "";
echo gettype($arr);//array
echo $arr["首都"];
echo ""; print_r($arr); echo ""; echo gettype($a);//NULL ?>
< >= <= == === != <> !==
* 逻辑运算符:&&(and) ||(or) !
* 三目运算符 条件? 真:假
* 赋值运算符:= += -= *= /= %=
*/
//++在前:在赋值时,先把$a加1,在赋值给$b
$a = 1;
++$a;
echo $a;//2
$b = ++$a;
echo $a,$b;//3 3
//++在后:在赋值时,先赋值给$b,在把$b加1
$a = 1;
$a++;
echo $a;//2
$b = $a++;
echo $a,$b;//3,2
//关系运算符
$a = 10;
$b = "10";
$c = 10;
$d = 5;
$f = "5";
//!= (写作<>):无论声明类型,只要两个值不一样,就说不等于
var_dump($a != $b);//false , !=是==取反
var_dump($a != $c);//false , !=是==取反
var_dump($a != $d);//true
var_dump($a != $f);//true
//!==:两个变量的类型或者值有一个不一样,就是不相等
var_dump($a !== $c);//false
var_dump($a !== $d);//true
var_dump($a !== $b);//true
var_dump($a !== $f);//true
$a = 3;
$b = 4;
$c = 5;
$res = $a > $b and $a < $c or $c < $b;
var_dump($res);//false
var_dump(!$a);//false
$a = "hi,";
$b = "Alice";
echo $a.$b;//字符串拼接运算符.
$a.=$b;
echo $a;
$a = 10;
$b = 5;
echo $a>$b?"是假的":"是假的";//是假的
?>
";
switch ($num) {
case 1:
echo "num为1";
break;
case 2:
echo "num为2";
break;
case 3:
echo "num为3";
break;
case 4:
echo "num为4";
break;
default:
//当以上所有条件都不满足时,取default
echo "1-4之外的数";
break;
}
//使用for循环输出从1到10
echo "
";
for($i = 1; $i<=10; $i++){
echo $i."
";
}
//while
/*
* while(条件){
* 条件完成时,此处每次都执行
* 必须要有个条件不满足的操作
* }
*/
//死循环
//while(true){
// echo "hi"."
";
//}
$num = 1;//初始值
while($num <= 10){
echo $num."
";
$num++;
}
//do-while
/*
* do{
* 做的内容
* }while(条件){
* 先执行代码,在判断条件满足不满足
* 特点:即使条件不满足,也会开启第一次循环
* }
*/
do{
echo "I am not 满足条件";
}while(false);
echo "
";
$num = 1;
do{
echo $num."
";
$num ++;
}while($num <= 10);
?>