1.array_shfit 將陣列開頭的單元移除陣列
$arr1=array('hh','ss','cc');
$arr2=array_shift($arr1);
print_r($arr1);
2.array_slice 從陣列中取出一段
$arr2=array_slice($arr1,2);
$arr3=array_slice($arr1,-2,1);
$arr4=array_slice($arr1,0,3);
$arr5=array_slice($arr1,2,-2);
$arr6=array_slice($arr1,2,-2,true);
print_r($arr2);
print_r($arr3);
print_r($arr4);
print_r($arr5);
print_r($arr6);
3.array_change_key_case 將陣列中的所有jiang
$arr1=array('hHH'=>'123','Cc'=>'245');
$arr2=array_change_key_case($arr1,CASE_UPPER);
$arr3=array_change_key_case($arr1,CASE_LOWER);
var_dump($arr2);
var_dump($arr3);
4.array_splice 去掉陣列中的某一部分並用其它陣列取代
$arr1=array('hHH'=>'123','Cc'=>'245','11'=>'cc','ss'=>'11');
array_splice($arr1,2);
print_r($arr1);
$arr1=array('hHH'=>'123','Cc'=>'245','11'=>'cc','ss'=>'11');
array_splice($arr1,1,-1);
print_r($arr1);
$arr1=array('hHH'=>'123','Cc'=>'245','11'=>'cc','ss'=>'11');
array_splice($arr1,1,count($arr1),'CESHI');
print_r($arr1);
$arr1=array('hHH'=>'123','Cc'=>'245','11'=>'cc','ss'=>'11');
array_splice($arr1,-1,1,array('come on','you can you up'));
print_r($arr1);
$arr1=array('hHH'=>'123','Cc'=>'245','11'=>'cc','ss'=>'11');
array_splice($arr1,3,0,'yes');
print_r($arr1);
5.array_sum 付陣列中所有值求和
$arr1=array(2,4,6,8);
var_dump(array_sum($arr1));
$arr2=array('a'=>1.2,'b'=>2.3,'c'=>3.4);
var_dump(array_sum($arr2));
本作品採用《CC 協議》,轉載必須註明作者和本文連結
The sun is always behind the storm~