From c0f2a89236daaa58df68a343c20311880650331b Mon Sep 17 00:00:00 2001 From: kuangweijian <867034892@qq.com> Date: Mon, 7 Mar 2022 19:33:32 +0800 Subject: [PATCH] =?UTF-8?q?php=E5=AD=A6=E4=B9=A0=E7=AC=AC=E4=B8=80?= =?UTF-8?q?=E5=A4=A9:=E5=9F=BA=E6=9C=AC=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- 01基本语法/constants常量.php | 28 +++++++++++++++++++++++++++ 01基本语法/global.php | 24 +++++++++++++++++++++++ 01基本语法/static_variables.php | 16 +++++++++++++++ 01基本语法/variable_variables.php | 10 ++++++++++ 01基本语法/定界符.php | 17 ++++++++++++++++ 01基本语法/运算符.php | 15 ++++++++++++++ 01基本语法/预定义变量.php | 8 ++++++++ 02流程控制/break_n.php | 26 +++++++++++++++++++++++++ 02流程控制/demo.php | 3 +++ 02流程控制/foreach.php | 17 ++++++++++++++++ 02流程控制/include.php | 4 ++++ 02流程控制/include_once.php | 5 +++++ 02流程控制/inlude2.php | 3 +++ 02流程控制/require.php | 4 ++++ 03函数/01参数是class.php | 11 +++++++++++ 03函数/03可变参数.php | 8 ++++++++ 03函数/declare.php | 9 +++++++++ 17 files changed, 208 insertions(+) create mode 100644 01基本语法/constants常量.php create mode 100644 01基本语法/global.php create mode 100644 01基本语法/static_variables.php create mode 100644 01基本语法/variable_variables.php create mode 100644 01基本语法/定界符.php create mode 100644 01基本语法/运算符.php create mode 100644 01基本语法/预定义变量.php create mode 100644 02流程控制/break_n.php create mode 100644 02流程控制/demo.php create mode 100644 02流程控制/foreach.php create mode 100644 02流程控制/include.php create mode 100644 02流程控制/include_once.php create mode 100644 02流程控制/inlude2.php create mode 100644 02流程控制/require.php create mode 100644 03函数/01参数是class.php create mode 100644 03函数/03可变参数.php create mode 100644 03函数/declare.php diff --git a/01基本语法/constants常量.php b/01基本语法/constants常量.php new file mode 100644 index 0000000..02032b1 --- /dev/null +++ b/01基本语法/constants常量.php @@ -0,0 +1,28 @@ +'; //常量没有$号 + echo b.'
'; + + //b=3; //b是常量,不能再修改 + //echo b; + + //获取常量 + $b='b'; + echo constant($b).'
'; + + //判断常量是否存在 + const c=3; + $d=4; + var_dump(defined('c')); //常量c存在,返回true + echo '
'; + var_dump(defined('d')); //d不是常量,返回false + echo '
'; + + //魔术常量 + echo "当前文件路径".__FILE__; + + /* + 感悟:php常量像C语言里的宏 + */ +?> \ No newline at end of file diff --git a/01基本语法/global.php b/01基本语法/global.php new file mode 100644 index 0000000..91665e3 --- /dev/null +++ b/01基本语法/global.php @@ -0,0 +1,24 @@ + b:$b"; + echo "
c:$c"; + } + + function func2() + { + echo "
a:".$GLOBALS['a']; // $GLOBALS['var'] 指的是函数外部变量本身,是一个变量.在程序的任意位置都能使用 + echo "
b:".$GLOBALS['b']; + echo "
c:".$GLOBALS['c']; + } + + func(); + echo "
"; + func2(); +?> \ No newline at end of file diff --git a/01基本语法/static_variables.php b/01基本语法/static_variables.php new file mode 100644 index 0000000..8d86bdf --- /dev/null +++ b/01基本语法/static_variables.php @@ -0,0 +1,16 @@ +"; //每当func()结束后,静态变量a的生命周期没有结束掉,不断的在原来的数值上+1,而b的生命周期结束了,每次调用func都是0 + } + + func(); + func(); + func(); + + echo $a; //但是静态变量作用域和局部变量是一样的,在作用域之外是不能使用的 +?> + diff --git a/01基本语法/variable_variables.php b/01基本语法/variable_variables.php new file mode 100644 index 0000000..17e3deb --- /dev/null +++ b/01基本语法/variable_variables.php @@ -0,0 +1,10 @@ +'; + + $$a='world'; //=>${$a}='world' =>($a='hallo')=> $hallo='world' + echo $$a.'
'; + + echo ${$a}.'
'; +?> \ No newline at end of file diff --git a/01基本语法/定界符.php b/01基本语法/定界符.php new file mode 100644 index 0000000..395514d --- /dev/null +++ b/01基本语法/定界符.php @@ -0,0 +1,17 @@ + + + + $title + + + hello world! + + + str; + + echo $str; +?> \ No newline at end of file diff --git a/01基本语法/运算符.php b/01基本语法/运算符.php new file mode 100644 index 0000000..86c7464 --- /dev/null +++ b/01基本语法/运算符.php @@ -0,0 +1,15 @@ +'; + } + + $c=10; + $d=10; + if($c===$d) + { + echo 'c的类型和值等于d的类型和值'.'
'; + } +?> \ No newline at end of file diff --git a/01基本语法/预定义变量.php b/01基本语法/预定义变量.php new file mode 100644 index 0000000..d868df3 --- /dev/null +++ b/01基本语法/预定义变量.php @@ -0,0 +1,8 @@ +"; + var_dump($_SERVER); +?> \ No newline at end of file diff --git a/02流程控制/break_n.php b/02流程控制/break_n.php new file mode 100644 index 0000000..3118bfc --- /dev/null +++ b/02流程控制/break_n.php @@ -0,0 +1,26 @@ +'; + if($i==5) + { + break 2;//跳出第2层循环,进入第三层循环; + } + echo "第1层循环
"; + } + echo "第2层循环
"; + } + echo "第3层循环
"; + break; + } + echo "第4层循环
"; + break; + } +?> \ No newline at end of file diff --git a/02流程控制/demo.php b/02流程控制/demo.php new file mode 100644 index 0000000..49c02f8 --- /dev/null +++ b/02流程控制/demo.php @@ -0,0 +1,3 @@ +'; +?> \ No newline at end of file diff --git a/02流程控制/foreach.php b/02流程控制/foreach.php new file mode 100644 index 0000000..3855139 --- /dev/null +++ b/02流程控制/foreach.php @@ -0,0 +1,17 @@ +'kwj','age'=>'30','native'=>'dongguan']; + + //遍历数组值 + foreach($array as $value){ + echo $value; + echo '
'; + } + + echo '------
'; + + //遍历键名和键值 + foreach($array as $key=>$value){ + echo "$key : $value"; + echo '
'; + } +?> \ No newline at end of file diff --git a/02流程控制/include.php b/02流程控制/include.php new file mode 100644 index 0000000..4b25d55 --- /dev/null +++ b/02流程控制/include.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/02流程控制/include_once.php b/02流程控制/include_once.php new file mode 100644 index 0000000..f515b57 --- /dev/null +++ b/02流程控制/include_once.php @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/02流程控制/inlude2.php b/02流程控制/inlude2.php new file mode 100644 index 0000000..c68b503 --- /dev/null +++ b/02流程控制/inlude2.php @@ -0,0 +1,3 @@ + \ No newline at end of file diff --git a/02流程控制/require.php b/02流程控制/require.php new file mode 100644 index 0000000..119258b --- /dev/null +++ b/02流程控制/require.php @@ -0,0 +1,4 @@ + \ No newline at end of file diff --git a/03函数/01参数是class.php b/03函数/01参数是class.php new file mode 100644 index 0000000..8c8716e --- /dev/null +++ b/03函数/01参数是class.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/03函数/03可变参数.php b/03函数/03可变参数.php new file mode 100644 index 0000000..72cac8b --- /dev/null +++ b/03函数/03可变参数.php @@ -0,0 +1,8 @@ +'; + func(1,2,3); + func(4,5,6,7,8); +?> \ No newline at end of file diff --git a/03函数/declare.php b/03函数/declare.php new file mode 100644 index 0000000..3f03419 --- /dev/null +++ b/03函数/declare.php @@ -0,0 +1,9 @@ + \ No newline at end of file