/* 陣列的常用函數
*
* 陣列的排序函數
* sort()
* rsort()
* uasort()
* ksort()
* krsort()
* uksort()
* uatsort()
* natcasesort()
array_multis * sort() rsort()
* 2.依鍵名對陣列排序
* ksort() krsort()
* 3.依元素的數值對陣列排序
* natsort()//區分大小寫字母比較natcasescort()//不區分大小寫字母的比較
* 5.根據使用者自訂規則對陣列排序
* usort() uasort() uksort()對鍵 usort() uasort() uksort()對鍵 .的排序
* array_multisort()
*
* 分割、合併、分解、接合的陣列函數
* .array_combine()//合併
* 4.array_merge();//合併
* 5.array_intersect();//多個陣列的交集
* 6.array_diff();////多個陣列的差的函數
* 1.使用陣列實現堆疊//先進後出
* array_push() array_pop()
*
*
* 其他與陣列運算相關的函數
* * 其他與陣列運算相關的函數
* array_rand()
* shuffle()
*
//簡單陣列排序的使用
$data=array(5,8,1,7,2);
sort($data);//元素由小到大進行排序
print_r($data);// Array ( [0] => 1 [1] => 2 [2] => 5 [3] => 7 [4] => 8 )
rsort($data);//元素由大到小進行排序
print_r($data);//Array ( [0] => 8 [1] => 7 [2] => 5 [3] => 2 [4] => 1 )
//依鍵名排序的範例
$data_2=array(5=>"five",8=>"eight",1=>"one",7=>"seven",2=>"two") ;
ksort($data_2);//對數組的下標進行由小到大排序
print_r($data_2);//Array ( [1] => one [2] => two [5] => five [7] => seven [8] => eight )
krsort($data_2);//對陣列的下標進行由大到小排序
print_r($data_2);//Array ( [8] => eight [7] => seven [5] => five [2] => two [1] => one )
$data_3=array("1"=>"Linux","a"=>"Apache","m"=>"MySQL","l"=>"PHP ");
//asort() arsort 與sort() rsort()的差別在於前者排序後保持原有的鍵名,後者不保持原有鍵名,且鍵名從0開始
asort($data_3 );
print_r($data_3);//Array ( [a] => Apache [1] => Linux [m] => MySQL [l] => PHP )
echo '
';
print_r($data_3);//Array ( [l] => PHP [m] => MySQL [1] => Linux [a] => Apache )
echo '
';
sort($data_3);
print_r($data_3);//Array ( [0] => Apache [1] => Linux [2] => MySQL [3] => PHP )
echo '
rsort($data_3);
print_r($data_3);//Array ( [0] => PHP [1] => MySQL [2] => Linux [3] => Apache )
//根據」自然數排序法「對陣列排序(0-9短者優先)
$data_4=array("file.txt","file11.txt","file2.txt","file22.txt") ;
sort($data_4);
print_r($data_4);//Array ( [0] => file.txt [1] => file11.txt [2] => file2.txt [3] => file22. txt )
echo '
';
natsort($data_4);
print_r($data_4);//Array ( [0] => file.txt [2] => file2.txt [1] => file11.txt [3] => file22.txt )
echo '
';
natcasesort($data_4);
print_r($data_4);//Array ( [0] => file.txt [2] => file2.txt [ 1] => file11.txt [3] => file22.txt )
echo '
';
//使用者自訂排序函數
echo '
';
$data_5=array("Linux","Apache","MySQL","PHP");
usort($data_5,"sortbylen");//透過元素長度排序
print_r($data_5);//Array ( [0] => PHP [1] => MySQL [2] => Linux [3] => Apache )
function sortbylen($one,$two) {
if(strlen($one)==strlen($two))
return 0;
else
return (strlen($one)>strlen($two))?1:-1;
}
//分割、合併、分解、接合的陣列函數
echo '
';
$data_6=array("Linux","Apache","MySQL","PHP");
print_r(array_slice($data_6 ,1,2));//取下標為1、2的元素
//Array ( [0] => Apache [1] => MySQL ) 下標重設從0開始
echo '
';
print_r(array_slice($data_6,-2,1));//從後邊的第二個開始取回一個,不是從0開始的
//Array ( [0] => MySQL ) 下標重置從0開始
echo '
';
print_r(array_slice($data_6,1,2,true));
//Array ( [1] => Apache [2] => MySQL ) 保留原有的下標
echo '
';
//array_combine()
$a1=array("OS","WebServer","DataBase","Language");
$a2=array("Linux","Apache","MySQL","PHPSQL","PHPSQL ");
print_r(array_combine($a1,$a2));//第一個參數作為鍵名,第二個作為值來合併
//Array ( [OS] => Linux [WebServer] => Apache [DataBase] => MySQL [Language] => PHP )
echo '
';
//array_merge()
$a3=array("OS","WebServer","DataBase","Language");
$a4=array("Linux","Apache","MySQL","PHPMy" );
$a5=$a3+$a4;
print_r($a5);//因為兩個陣列下標重複所以顯示這樣
//Array ( [0] => OS [1] => WebServer [2] => DataBase [3] => Language )
echo '
';
print_r(array_merge($a3,$a4));//合併重新索引
//Array ( [0] => OS [1] = > WebServer [2] => DataBase [3] => Language [4] => Linux [5] => Apache [6] => MySQL [7] => PHP )
echo '
';
//array_intersect()
$a7=array("OS","WebServer","DataBase","Language",1,2,3);
$a8=array("Linux","Apache"," MySQL","PHP",2,3,4);
print_r(array_intersect($a7,$a8));//Array ( [5] => 2 [6] => 3 )
echo '
';
//array_diff()
$a9=array(1,2,3,4);
$a10=array(3,4,5,6);
print_r(array_diff($a9,$a10));/ /Array ( [0] => 1 [1] => 2 )
//傳回第一個陣列跟第二個相差的元素
echo '
';
//使用陣列實作堆疊
$b=array(1,2,3,4);
$b[]="a";//入棧
array_push($b,"b","c" );//使用函數入棧
print_r($b);//Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => a [ 5] => b [6] => c )
echo '
';
$value=array_pop($b);//使用函數出棧
print_r($b);//Array ( [0] => 1 [1] => 2 [2] => 3 [3] => 4 [4] => a [5] => b )
echo '
';
echo $value;//顯示出堆疊的元素的值c
echo '
';
//使用陣列實作佇列
$c=array(1,2,3);
print_r($c);//Array ( [0] => 1 [1] => 2 [2] => 3 )
echo '
';
array_unshift($c,"abc","bcd");//入隊
print_r($c);//Array ( [0] => abc [1] => bcd [2 ] => 1 [3] => 2 [4] => 3 )
echo '
';
$values=array_shift($c);//出隊
print_r($c);// Array ( [0 ] => bcd [1] => 1 [2] => 2 [3] => 3 )
echo '
';
unset($c[2]);//刪除指定位置元素
print_r($c );//Array ( [0] => bcd [1] => 1 [3] => 3 )
echo '
';
//array_rand() 隨機回傳數組下標
$arr=array(1,3,4,5,76,7,99,6,2,3);
echo array_rand($arr);//返回的是隨機的數組元素的下標
echo $arr[array_rand($arr)];//隨機顯示數組元素的值
echo '
';
//shuffle() 隨機重新排列數組
$arr2=array (32,35,33);
shuffle($arr2);
print_r($arr2);//陣列元素位置隨機轉換
echo '
';
//array_sum() 求和
$arr3=array(1 ,3,5);
echo array_sum($arr3); //回傳9
echo '
';
print_r($arr3);//Array ( [0] => 1 [1] => 3 [2] => 5 )
echo '
';
//range(最小值,最大值,步長)
$arr4=range(0,100,10);
print_r($arr4);//Array ( [0] = > 0 [1] => 10 [2] => 20 [3] => 30 [4] => 40 [5] => 50 [6] => 60 [7] => 70 [8] => 80 [9] => 90 [10] => 100 )
?>
判斷類型的函數:::::::
str_類型的函數
str_split(
$str [,$len=1]);//將字串轉換成一個陣列
//轉換成浮點型 intval($str); //轉換成整數
🎜🎜🎜 🎜 🎜🎜🎜🎜🎜轉換大小寫🎜🎜🎜🎜🎜去除html的標籤的函數
ASCII轉換數字 陣列轉換ASCII
去除空格
trim(string $str [,string $charlist ]); //去左右字符$charlist ]); //去左右字符
魔術方法
__construct
__destruct
__set
__unset
__isset
__get
__debuginfo
__invoke
__call
__sleep
__wakeup
__clone
__toString
常見的設計模式
單例 工廠 注入 觀察者 策略 工廠方法 適配器 等;;;;
常用的資料庫:
ORACLE (甲骨文); MySQL; SQLServer; 等
這只是大致的概括 暫時就想起來這些,希望能夠幫到一些初學者! !
適合初學者 有需要的可以評論裡提出來!
後期會一直更新! ! ! ! ! ! ! ! ! ! !