PHP学习笔记(一)——行云博客

文章目录

        • 1st
        • 2nd
        • 3rd
        • 4th
        • 5th
        • 6th
        • 7th
        • 8th
        • 9th
        • 10th
        • 11th
        • 12th
        • 13th
        • 14th
        • 15th
        • 16th

1st

php代码内可以包含html内容,或者说php脚本文件内php解释器仅仅解释PHP







2nd



我的第一张PHP页面

3rd

php的三种注释







4th

用户定义的函数、类和关键词大小写不敏感;
变量大小写敏感。


  echo "haha";
  ECHO "HAHA";
  eCHO "haha";
  $color = 'red';
  $Color = 'green';
  $COLOR = 'yellow';
  echo 'the color is '.$color;
  echo 'the color is '.$Color;
  echo 'the color is '.$COLOR;
?>

5th

php变量以$开头,变量名以字母或下划线开头,可以含有数字


6th

php变量类型松散,定义时变量一个类型,在之后可以赋予另一种类型的参数。
三种作用域:local、global、static
global关键字用在函数内变量前表示声明以后使用的变量为全局变量。
static关键字用在函数内变量前表示该变量在函数执行完成后不销毁,且static关键字定义的变量赋予的仅是初始值,再次执行函数,不会执行定义中的赋值操作。

";
	echo "变量y是:$y
"; echo "变量s是:$s
"; } myTest(); myTest(); myTest(); ?>

7th

echo为php的一个结构,print可以看作一个函数,有返回值,var_dump()函数可以输出内容和类型
单双引号的区别

";
	echo print('$x is $x');
?>

输出:

$x is haha
$x is $x
1

8th

整数、浮点数表示方法


输出:
int(1) float(2000) int(26) int(15)

9th

php数组
普通数组定义

$cars = array("BMW", "SAAB");
var_dump($cars);

$cars[0]="Volvo";
$cars[1]="BMW";
$cars[2]="Toyota";

关联数组定义

$age=array("Peter"=>"35", "Ben"=>"37", "Joe"=>"43");

或者

$age['Peter']="35";
$age['Ben']="37";
$age['Joe']="43";

使用
$age['Peter'];
或者

foreach($age as $x=>$x_value){
    echo "Key=" . $x . ", Value=" . $x_value;
    echo "
"; }

10th

类的定义及对象的使用(个人扩展)

Object created! 

The car's color is $color.
"; $this->color = $color; } function __destruct(){ echo "
==>Object teminated!
"; } function get_color(){ return $this->color; } function set_color($color){ $this->color = $color; echo "The car's color is set to $color.
"; } } $car = new Car("red");//构造函数有一个变量,new对象时应该赋予参数 $car->set_color("white"); ?>

输出

==>Object created! 

The car's color is red.
The car's color is set to white.

==>Object teminated!

11th

php字符串函数

';
	echo strpos("Hello, World!", "World");
?>

输出

5
7

12th

php使用define()函数定义常量, 默认不敏感(FALSE),要让敏感才设置TRUE
define('COUNTRY', 'CN', TRUE); //大小写敏感
使用
echo COUNTRY;

13th

php运算符:算数运算符、赋值运算符、字符串运算符、递增减运算符、比较运算符、逻辑运算符、数组运算符
%、.、.=、++、--、===、!=、!==、and、or、xor、&&、||、!

14th

php数组的联合及比较

"white", "MAZIDA"=>"yellow");
$b = array("BMW"=>"black", "car"=>"yellow");
$c = $a + $b;   //键名一样只取前者,后者忽略
var_dump($a == $b);
var_dump($a === $b);
var_dump($c);
?>

输出
bool(false) bool(false) array(3) { ["BMW"]=> string(5) "white" ["MAZIDA"]=> string(6) "yellow" ["car"]=> string(6) "yellow" }

15th

if、else、elseif语句

= 0 && $s <= 100){
	if($s < 60){
		echo "很差!";
	}
	elseif($s < 80){
		echo "普通!";
	}
	elseif($s <= 100){
		echo "高手";
	}
}
else echo "参数有误!";
?>

16th

switch语句


你可能感兴趣的:(PHP交流,学习技术,php)