The basic syntax of
<head> <meta charset="UTF-8"> <title>Second Php</title> </head> <?php /** * Created by PhpStorm. * User: liyanq * Date: 16/7/5 * Time: 13:15 */ /* * 1,什么头都不加的话,显示乱码,知道是编码格式问题,拷过来就好了;但还不了解上面语法,以后再说吧. * 2,汉字的排序不是按照拼音的首字母来的. * 3,sort,rsort普通数组;asort,ksort,arsort,krsort关联数组; * */ $names = array("梅西","c罗","贝尔"); $nameAndage = array("梅西"=>29,"C罗"=>31,"贝尔"=>26); function NormalarrToStr($arr){ $r = ""; for ($x = 0; $x < count($arr); $x ++){ $r = $r . " " . $arr[$x];//用.链接字符串真别扭啊~! } return $r; } function KeyValueArrToStr($arr){ $r = ""; foreach($arr as $x => $xValue){ $r = $r . " " . "[$xValue]$x"; } return $r; } echo "排序前:",NormalarrToStr($names),"<br>"; sort($names); echo "排序后:",NormalarrToStr($names),"<br>"; echo "排序前:",KeyValueArrToStr($nameAndage),"<br>"; ksort($nameAndage); echo "排序后:",KeyValueArrToStr($nameAndage),"<br>"; /* * 1,$GLOBALS是一个包含了全部变量的全局组合数组。变量的名字就是数组的键; * 2,$GLOBALS里面的内容都挺有用的.可以搜集客户信息.http://www.runoob.com/php/php-superglobals.html * 3,$_REQUEST能够获取HTML表单提交的数据,只要知道Input的名字即可.可理解2页面的通讯通道; * */ $x = 25;$y=75; function TestGlobals(){ global $x; $GLOBALS['z'] = $x + $GLOBALS['ya']; } TestGlobals(); echo $z,'<br>'; echo $_SERVER["PHP_SELF"],'<br>'; echo $_SERVER["SERVER_NAME"],'<br>'; echo $_SERVER["HTTP_HOST"],"<br>"; echo $_SERVER["SERVER_ADDR"],"<br>"; echo $_SERVER["REQUEST_METHOD"],"<br>"; echo $_SERVER["REMOTE_ADDR"],"<br>"; echo $_SERVER["SCRIPT_FILENAME"],"<br>"; ?> <!--1,才知道form里的Action里面的Echo是起到页面导航用的.--> <!--2,不写或者echo $_SERVER["PHP_SELF"];都是提交后返回自己页面.--> <!--3,导航其他页面,不用写绝对路径.--> <!--显示Post提交的内容:$_REQUEST和POST是一对儿;--> <form method="post" action="<?php echo $_SERVER["PHP_SELF"]; //echo "FirstHello.php"; ?>"> <h3>Name:</h3> <input type="text" name="Text1"> <input type="submit" name="Button1"> <input type="time"> </form> <?php $InputText = $_REQUEST["Text1"]; $InputStr = $_REQUEST["Button1"]; echo "POST提交内容:", $InputText, $InputStr ,"<br>"; ?> <!--显示Get提交的内容:$_GET和GET是一对儿;--> <a href="<?php print $_SERVER["PHP_SELF"];?>?Param1=参数1&Param2=参数2">测试GET</a> <?php echo "Get Param1:" . $_GET['Param1'] . "Get Param2: " . $_GET['Param2'] . "<br>"; ?> <?php function TestVar(&$var){ $var++; echo "__FUNCTION__:",__FUNCTION__,"<br>"; } $x = 1; TestVar($x); echo $x . "<br>";//结果是2,&传址; echo "__Line__:",__LINE__,"__File__:",__FILE__,"<br>"; echo "__Dir__:",__DIR_,"<br>"; class TestGlobalVar{ function MyFun1(){ echo "__FUNCTION__",__FUNCTION__, ";__Class__:",__CLASS__,"<br>"; } } $V1 = new TestGlobalVar(); $V1->MyFun1(); class MyBase{ function SayHello(){ echo "Hello"; } } //trait这个语法没有见到过,需要留意下.~ trait TraitSay{ public function SayHello(){ parent::SayHello(); echo "World"; } } class MyChild extends MyBase{ use TraitSay; } $c = new MyChild(); $c->SayHello(); ?>
The above introduces [php learning 2] basic grammar exercise 2, including aspects of content. I hope it will be helpful to friends who are interested in PHP tutorials.