用二十秒記住幾個PHP基礎知識點

來源:互聯網
上載者:User

標籤:ext   基礎   返回   java   輸出   sdn   art   imp   個數   

數組:
索引數組:數組的鍵是整數的數組,從0開始。


關聯陣列:數組的鍵是字串的數組

//索引數組$arr=array(‘I‘,‘love‘,‘you‘);//關聯陣列$arr0=array(‘apple‘=>"蘋果",‘yellow‘=>"黃色");

foreach遍曆數組

//數組的遍曆$arr=array("蘋果","黃色");foreach($arr as $key=>$value){    echo ‘<br>鍵是:‘.$key.‘相應的值是:‘.$value;      }$arr0=array(‘apple‘=>"蘋果",‘yellow‘=>"黃色");foreach($arr0 as $key=>$value){    echo ‘<br>鍵是:‘.$key.‘,相應的值是:‘.$value;}

推斷函數是否存在:function_exsits(函數名)

function sayHello(){    echo ‘hello‘;}$test=‘sayHello‘;if(function_exsits($test)){    sayHello();}//輸出hello

建構函式:對象建立時調用的方法
解構函式:對象銷毀時調用的方法

class Car(){    public __construct(){        echo ‘對象已經建立‘;    }    public __destruct(){        echo ‘對象已經銷毀‘;    }}$car=new Car();

strpos:尋找字串的方法

$str=‘hello world‘;echo strpos($str,‘world‘);//輸出6,從第6位開始

implode:傳回值:把數組元素組合成一個字串

$arr = array(‘abc‘, ‘defg‘);$arr0 = implode(‘‘, $arr);print_r($arr0);//結果顯示abcdefg

explode:傳回值:函數返回由字串組成的數組

$str="abc,defg";$arr=explode(‘,‘,$str);print_r($arr); //結果返回一個數組,裡面有兩個元素: abc和defg

本文作者:By:羅堅元 http://blog.csdn.net/sunyuan_software

用二十秒記住幾個PHP基礎知識點

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.