共計(jì) 842 個(gè)字符,預(yù)計(jì)需要花費(fèi) 3 分鐘才能閱讀完成。
php 中常用的原生函數(shù)有以下幾種
1.array_unique 函數(shù)
array_unique 函數(shù)作用:
php 中 array_unique 函數(shù)的作用是用于移除數(shù)組中的重復(fù)的值,并返回結(jié)果數(shù)組。
array_unique 函數(shù)語(yǔ)法:
array_unique(array)
array_unique 函數(shù)使用方法:
$a=array("a"=>"Cat","b"=>"Dog","c"=>"Cat");
print_r(array_unique($a));
>>>Array ([a] => Cat [b] => Dog )
2.explode 函數(shù)
explode 函數(shù)作用:
php 中 explode 函數(shù)的作用是將一個(gè)字符串轉(zhuǎn)換成數(shù)組,并輸出。
explode 函數(shù)語(yǔ)法:
explode(separator,string)
參數(shù):
separator:分割字符串的位置。
explode 函數(shù)使用方法:
$str = "Hello world!";
print_r (explode(" ",$str));
>>> array(Hello, world!)
3.array_sum 函數(shù)
array_sum 函數(shù)作用:
php 中 array_sum 函數(shù)的作用是返回?cái)?shù)組中所有值的總和。
array_sum 函數(shù)語(yǔ)法:
array_sum(array)
array_sum 函數(shù)使用方法:
$a=array(0=>"5",1=>"15",2=>"25");
echo array_sum($a);
>>>45
4.array_merge 函數(shù)
array_merge 函數(shù)作用:
php 中 array_merge 函數(shù)的作用是將多個(gè)數(shù)組合并為一個(gè)數(shù)組。
array_merge 函數(shù)語(yǔ)法:
array_merge(array1,array2)
array_merge 函數(shù)使用方法:
$a1=array("a"=>"red","b"=>"green");
$a2=array("c"=>"blue","b"=>"yellow");
print_r(array_merge($a1,$a2));
丸趣 TV 網(wǎng) – 提供最優(yōu)質(zhì)的資源集合!