31,"贝尔"=>26);function NormalarrToStr($arr){ $r = ""; for ($x = 0; $x $xValue){ $r = $r">
当前位置:Gxlcms > PHP教程 > [php学习二]基本语法练习二

[php学习二]基本语法练习二

时间:2021-07-01 10:21:17 帮助过:20人阅读


    
    Second Php

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),"
"; sort($names); echo "排序后:",NormalarrToStr($names),"
"; echo "排序前:",KeyValueArrToStr($nameAndage),"
"; ksort($nameAndage); echo "排序后:",KeyValueArrToStr($nameAndage),"
"; /* * 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,'
'; echo $_SERVER["PHP_SELF"],'
'; echo $_SERVER["SERVER_NAME"],'
'; echo $_SERVER["HTTP_HOST"],"
"; echo $_SERVER["SERVER_ADDR"],"
"; echo $_SERVER["REQUEST_METHOD"],"
"; echo $_SERVER["REMOTE_ADDR"],"
"; echo $_SERVER["SCRIPT_FILENAME"],"
"; ?> "; ?> ?Param1=参数1&Param2=参数2">测试GET "; ?> "; } $x = 1; TestVar($x); echo $x . "
";//结果是2,&传址; echo "__Line__:",__LINE__,"__File__:",__FILE__,"
"; echo "__Dir__:",__DIR_,"
"; class TestGlobalVar{ function MyFun1(){ echo "__FUNCTION__",__FUNCTION__, ";__Class__:",__CLASS__,"
"; } } $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(); ?>
基本语法差不多了。

以上就介绍了 [php学习二]基本语法练习二,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

人气教程排行