String:
求字符串长度:strlen();
将字符串转换为大写:strtoupper();
将字符串转换为小写:strtolower();
句首大写:ucfirst();
单词开头大写:ucwords();
$string1="I love PHP";
$len=strlen($string1);//求字符串的长度结果是10
$up=strtoupper($string1);//将字符串转换为大写,结果是:I LOVE PHP
$low= strtolower($string1);//将字符串转换为小写,结果是: i love php
$name="harry potter";
$name1= ucfirst($name);//将句子的首字母大写,结果是: Harry potter
$firstname= ucwords($name);//将单词的首字母大写,结果是:Harry Potter
字符串替换:
$sentence="Today is wonderful. I don't have class.";
$change1=str_replace(' ','',$sentence);//结果是:Todayiswonderful.Idon'thaveclass
$change2= str_replace(' ','***',$sentence);//结果是:Today***is***wonderful.***I***don't***have***class.
对字符串进行分割:
$sentence="Today is wonderful. I don't have class.";
$words= explode(' ',$sentence);
print_r($words);//结果如下:
//Array ([0] => Today [1] => is [2] => wonderful. [3] => I [4] => don't [5] => have [6] => class.)
Arrays:
Indexed arrays:
创建:
$book1=array(1,2,3,4);
$book2=[1,2,3,4];
增加:
array_push($book1,5);
$book2[]=5;
//在末尾插入5
删除、替换、排序:
array_pop($book1);//删除末尾元素
$book1[0]=1024;//替换
sort($book1);//排序
Associative arrays:
创建、添加、替换:
//创建book1 book2
$book1=["title"=>"Harry Port"];
$book2["title"]="The problem people faced today";
//book1 添加键值对
$book1["author"] ="Powers";
//将book1的键值对替换
$book1["title"]="C++ learning"
Multidimensional arrays:
创建:
$book1=["title"=>"Harry Port"];
$book2["title"]="The problem people faced today";
$books=[$book1,$book2]
//books就是Multidimensional arrays