PHP慣用功能

來源:互聯網
上載者:User
PHP常用功能

1)字串

主要方法有:strops()、substr()、str_split()、explode()等,更多方法查看PHP官方手冊;

';//字串的截取$str1=substr($str,4);$str2=substr($str,4,2);echo $str1.'
';echo $str2.'
';//字串的分割$result1=str_split($str);$result2=str_split($str,3);$result3=explode(' ',$str);print_r($result1);echo '
';print_r($result2);echo '
';print_r($result3);echo '
';//字串的串連$num=500;$str3="$str
from Hanhan $num";echo $str3;



2)數組

array_push()——用來儲存數組的值;

更多方法查看PHP官方手冊;

';echo $arr[2];echo '
';//數組的建立:用key-value方式建立$arr2=array();$arr2['h']='hello';$arr2['w']='world';print_r($arr2);echo '
';echo $arr2['h'];echo '
';//數組的初始化$arr3=array(0=>'jason',1=>'see','h'=>'hello','w'=>'world','name'=>'shydzc');echo $arr3['name'];echo '
';//數組的常用方法$arr4=array();for($i=0;$i<10;$i++){ array_push($arr4,'item '.$i);}print_r($arr4);




著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.