[TOC]
## **數組合并**
### PHP 數組相加 和 數組合并array_merge
```
$arr1 = array("a"=>"PHP","b"=>"java","python");
$arr2 = array("c" =>"ruby","d" => "c++","go","a"=> "swift");
$arr3 = array_merge($arr1,$arr2);
$arr4 = $arr1 + $arr2;
var_dump($arr3);
var_dump($arr4);
```
輸出:
```
array ( 'a' => 'swift', 'b' => 'java', 0 => 'python', 'c' => 'ruby', 'd' => 'c++', 1 => 'go', )
array ( 'a' => 'PHP', 'b' => 'java', 0 => 'python', 'c' => 'ruby', 'd' => 'c++', )
```
區別:
當下標為數值時,array\_merge()不會覆蓋掉原來的值,但arrayA+arrayB合并數組則會把最先值arrayA的值作為最終結果返回,而把arrayB數組擁有相同鍵名的那些值“拋棄”掉,而不是覆蓋
當下標為字符時,arrayA+arrayB 仍然把最先出現的值作為最終結果返回,而把后面的數組擁有相同鍵名的那些值“拋棄”掉,但array\_merge()此時會覆蓋掉前面相同鍵名的值
### [array\_?combine?($keysArr , $valuesArr);](https://www.php.net/manual/zh/function.array-combine.php "array_?combine")? 兩個數組分別作為新數組的鍵與值進行合并
## **數組排序**
### **排序函數一覽**
| 函數名稱 | 排序依據 | 數組索引鍵保持 | 排序的順序 | 相關函數 |
| --- | --- | --- | --- | --- |
| [array\_multisort()](https://www.php.net/manual/zh/function.array-multisort.php) | 值 | 鍵值關聯的保持,數字類型的不保持 | 第一個數組或者由選項指定 | [array\_walk()](https://www.php.net/manual/zh/function.array-walk.php) |
| [asort()](https://www.php.net/manual/zh/function.asort.php) | 值 | 是 | 由低到高 | [arsort()](https://www.php.net/manual/zh/function.arsort.php) |
| [arsort()](https://www.php.net/manual/zh/function.arsort.php) | 值 | 是 | 由高到低 | [asort()](https://www.php.net/manual/zh/function.asort.php) |
| [krsort()](https://www.php.net/manual/zh/function.krsort.php) | 鍵 | 是 | 由高到低 | [ksort()](https://www.php.net/manual/zh/function.ksort.php) |
| [ksort()](https://www.php.net/manual/zh/function.ksort.php) | 鍵 | 是 | 由低到高 | [asort()](https://www.php.net/manual/zh/function.asort.php) |
| [natcasesort()](https://www.php.net/manual/zh/function.natcasesort.php) | 值 | 是 | 自然排序,大小寫不敏感 | [natsort()](https://www.php.net/manual/zh/function.natsort.php) |
| [natsort()](https://www.php.net/manual/zh/function.natsort.php) | 值 | 是 | 自然排序 | [natcasesort()](https://www.php.net/manual/zh/function.natcasesort.php) |
| [rsort()](https://www.php.net/manual/zh/function.rsort.php) | 值 | 否 | 由高到低 | [sort()](https://www.php.net/manual/zh/function.sort.php) |
| [shuffle()](https://www.php.net/manual/zh/function.shuffle.php) | 值 | 否 | 隨機 | [array\_rand()](https://www.php.net/manual/zh/function.array-rand.php) |
| [sort()](https://www.php.net/manual/zh/function.sort.php) | 值 | 否 | 由低到高 | [rsort()](https://www.php.net/manual/zh/function.rsort.php) |
| [uasort()](https://www.php.net/manual/zh/function.uasort.php) | 值 | 是 | 由用戶定義 | [uksort()](https://www.php.net/manual/zh/function.uksort.php) |
| [uksort()](https://www.php.net/manual/zh/function.uksort.php) | 鍵 | 是 | 由用戶定義 | [uasort()](https://www.php.net/manual/zh/function.uasort.php) |
| [usort()](https://www.php.net/manual/zh/function.usort.php) | 值 | 否 | 由用戶定義 | [uasort()](https://www.php.net/manual/zh/function.uasort.php) |
### [**array\_?multisort**](https://www.php.net/manual/zh/function.array-multisort.php "array_?multisort") ( &$array1, mixed SORT_ASC, mixed SORT_REGULAR,&$array2, mixed SORT_ASC, mixed SORT_REGULAR, mixed $... = ? ): bool對多個數組或多維數組進行排序
參數1:要排序的array
參數2:之前array參數要排列的順序。**`SORT_ASC`**按照上升順序排序,**`SORT_DESC`** 按照下降順序排序
參數3:為array參數設定選項:
排序類型標志:
* **`SORT_REGULAR`**\- 將項目按照通常方法比較(不修改類型)
* **`SORT_NUMERIC`**\- 按照數字大小比較
* **`SORT_STRING`**\- 按照字符串比較
* **`SORT_LOCALE_STRING`**\- 根據當前的本地化設置,按照字符串比較。 它會使用 locale 信息,可以通過[setlocale()](https://www.php.net/manual/zh/function.setlocale.php)修改此信息。
* **`SORT_NATURAL`**\- 以字符串的"自然排序",類似[natsort()](https://www.php.net/manual/zh/function.natsort.php)
* **`SORT_FLAG_CASE`**\- 可以組合 (按位或 OR)**`SORT_STRING`**或者**`SORT_NATURAL`** 大小寫不敏感的方式排序字符串。
* ...更多參數:可選的選項,可提供更多數組,跟隨在 sort order 和 sort flag 之后。 提供的數組和之前的數組要有相同數量的元素。 換言之,排序是按字典順序排列的。
通常可以用此函數進行排名
```
$arr=[286,298,284,288];
array_multisort($arr,SORT_DESC,SORT_REGULAR);
array_multisort($arr,SORT_REGULAR,SORT_DESC);//數組之后跟的兩個參數可以呼互換
//[298,288,268,284]
```
示例 #2 排序多維數組
```
$ar = array(
array("10", 11, 100, 100, "a"),
array( 1, 2, "2", 3, 1)
);
array_multisort($ar[0], SORT_ASC, SORT_STRING,
$ar[1], SORT_NUMERIC, SORT_DESC);
var_dump($ar);
```
#### 對數據庫指定的列排序,這里指定cost_staus和subject兩個進行排序(太神奇了)
```
$newdata =[
['id' => 1,'cost_staus'="1",'subject'=>"營銷部"],
['id' => 2,'cost_staus'="1",'subject'=>"招待部"],
['id' => 3,'cost_staus'="0",'subject'=>"營業部"]
]
foreach ($newdata as $key => $row) {
$cost_staus[$key] = $row['cost_staus'];
$subject[$key] = $row['subject'];
}
//對這兩個進行升序,優先級以靠前的參數為主,其他字段傳入newdata按照普通排序
array_multisort($cost_staus, SORT_ASC, $subject, SORT_ASC, $newdata);
```
**示例 4: 不區分大小寫字母排序**
**`SORT_STRING`**和**`SORT_REGULAR`**都是區分大小寫字母的,大寫字母會排在小寫字母之前。
要進行不區分大小寫的排序,就要按照原數組的小寫字母拷貝來排序。
```
$array?=?array('Alpha',?'atomic',?'Beta',?'bank');
$array_lowercase?=?array_map('strtolower',?$array);
array_multisort($array_lowercase,?SORT_ASC,?SORT_STRING,?$array);
print_r($array);
```
輸出
~~~
Array
(
[0] => Alpha
[1] => atomic
[2] => bank
[3] => Beta
)
~~~
## **分割字符串為數組**
### explode
~~~
$str = "Hello world. I love Shanghai!";
print_r (explode(" ",$str));//Array ( [0] => Hello [1] => world. [2] => I [3] => love [4] => Shanghai! )
var_dump(explode('<=>','a<=>b c<=>d'));//array ( 0 => 'a', 1 => 'b c', 2 => 'd', )
~~~
### preg_split 多處分割
```
$str="FreeSpace=46627741696 Size=85897945088";
$res=preg_split("/[(Size=)|(FreeSpace=)]+/", trim($v),-1, PREG_SPLIT_NO_EMPTY);//PREG_SPLIT_DELIM_CAPTURE|PREG_SPLIT_OFFSET_CAPTURE
結果:
array ( 0 => '46627741696 ', 1 => '85897945088', )
```
**數組:**
>[danger]PHP使用explode和preg_split截取出來的數組,獲取指定下標時報錯:Undefined offset: 1
**解決辦法**
首先指定explode截取長度;然后使用array\_pad將未定義的數組長度的值補全,這里賦值為null
list($a, $b, $c, $d) = array\_pad(explode("-", $str, 4), 4, null);
方法2:添加錯誤抑制符@
>[danger]**注意:[array\_?walk\_?recursive](https://www.php.net/manual/zh/function.array-walk-recursive.php "array_?walk_?recursive")、?[array\_?merge\_?recursive](https://www.php.net/manual/zh/function.array-merge-recursive.php "array_?merge_?recursive")?、[array\_?replace\_?recursive](https://www.php.net/manual/zh/function.array-replace-recursive.php "array_?replace_?recursive")?支持多維數組,其他都是一維數組的操作?**
## **刪除及過濾**
### **array\_filter**($arr ,$callback \[, int $flag = 0 \]\] );//數組過濾刪除回調函數中返回fasle的數組
~~~
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
//ARRAY_FILTER_USE_KEY 只接受鍵
array_filter($arr, function($key) {
return $key == 'b'; #當為true時則保留
}, ARRAY_FILTER_USE_KEY); #['b'=>2]
//ARRAY_FILTER_USE_BOTH 接受鍵值
array_filter($arr, function($v, $key) {
return $key == 'b' || $v == 4;
}, ARRAY_FILTER_USE_BOTH); #['b'=>2,'d'=>4];
//只有一個參數時會將數組的值轉為boolean 為true 則保留,否則刪除
~~~
### 使用回調函數過濾數組的元素
~~~
$arr = array('foo', 5, 10, 'bar',false);//第一個參數數組的值作為填充數組的鍵,第二個參數作為值
$a=array_filter($arr ,function($value,$key){//如果沒有回調函數將刪除 array 中所有等值為 FALSE 的條目
if($key==1){
return false;//此函數內一定要有返回true,保留數組中返回true的元素
}else{
return true;
}
//return ==1;
},ARRAY_FILTER_USE_BOTH);//數組過濾刪除回調函數中返回fasle的數組值 存在ARRAY_FILTER_USE_BOTH時,回調函數同時接受鍵值兩個參數否則只接受key
/* 返回
array{
[0]=> "foo",
[2]=>10,
[3]=>"bar",
[4]=>false,
}
*/
$a=array_filter($arr);
/* 返回
array{
[0]=> "foo",
[1]=>5,
[2]=>10,
[3]=>"bar",
}
*/
~~~
獲取數組指定范圍的新數組
```
$arr=[1,2,3,4,5,6,7,8,9,10,11,12];
function getArrRangeValue($arr, $min, $max){
$newArr=array_filter($arr ,function($value,$key) use($min,$max){
if ($value>=$min && $value<=$max) {
return true;
}
},ARRAY_FILTER_USE_BOTH);
return $newArr;
}
$res=getArrRangeValue($arr,2,5);
print_r($res);//Array([1] => 2,[2] => 3,[3] => 4,[4] => 5)
```
### **array_splice**($arr,$start_index_int,$remove_length);//移除索引數組中指定位置及之后的length個元素,返回被移除的元素數組`
~~~
$arr=[1,2,3,4,5];
array_splice($arr,0,2);//返回[1,2] 此時$arr=[3,4,5]
~~~
### **unset**()函數刪除的話,數組的索引值沒有變化。
~~~
$arr=[1,2,3,4];
$unset($arr[1]);//arr=[0=>1,2=>3,3=>4]
~~~
### **array_pop**($arr);刪除最后一個元素(出棧)?
~~~
$stack = array("orange", "banana", "apple", "raspberry");
$fruit = array_pop($stack);
~~~
### **array_shift**(?`$arr`?);刪除第一個元素
~~~
$arr= array("orange", "banana", "apple", "raspberry");
$fruit = array_shift($arr);//[0=>'banana',1=>'apple',2=>'raspberry'];
~~~
## **數組元素追加**
### **array_splice**($arr,$start_index_int,$remove_length,$replace_arr);//$start_index_int,$remove_length組合不再$arr的范圍即不能刪除和替換時就插入
### $arr[]='value';
### **array_push**($arr,$value1,$value2,...);//尾部插入新單元(入棧) 就新增單元而言$arr\[\]=value 效率更高
?注意:array\_splice不保留鍵名每次都會截斷并重新生成索引鍵
### **array\_unshift**($arr,value1,$value2,$valueN...)? 數組的開頭插入value
## **隨機:**
### shuffle? 打亂數組
### array_rand($arr,5)? ? 重數組總共隨機抽取5個一維元素
## **鍵值互換**:
### **array_flip**($arr)
## **合并**
### [array_?merge](https://www.php.net/manual/zh/function.array-merge.php "array_?merge")
### [array_?merge\_?recursive](https://www.php.net/manual/zh/function.array-merge-recursive.php "array_?merge_?recursive")
## **拆分**
### **array_chunk**($arr,$size,false為不保留鍵)? ?按照每個$size個數拆分數組
### [**array_?chunk**($arr, $size, false);//[1,2,3,4]==>[[1,2],[3,4]]? ?分割成size大小的數組 第三個參數preserve_keys是否保留原鍵名](https://www.php.net/manual/zh/function.array-chunk.php "array_?chunk")
## **截取**
### **array_slice**($arr ,$start\_index [,$length = NULL [,$preserve_keys = false ]] );//length 為null 截取 start_index ~數組末尾的
~~~
$input = array("a", "b", "c", "d", "e");
#第二個參數為父則從數組末尾開始,第三個參數為負則截取在末尾至(-參數)位置之前的 第三參數為true則不重置數字索引
array_slice($input, 2); //[ "c", "d", "e"]
array_slice($input, -2, 1); // ["d"]
array_slice($input, 0, 3); //["a","b","c"]
array_slice($input, 2, -1); //[0=>'c',1=>'d']
array_slice($input, 2, -1, true);//[2=>'c',3=>'d']
~~~
## **數組元素替換(修改)**
### **array_splice**($arr,$start_index_int,$remove_length,$replace_arr);//第四個參數存在時不是移除而是修改`
### **array_replace_recursive**($arr,$arr1,$arrN);//遞歸替換$arr獨有保持不變,$arr1獨有則追加,同時存在則替換(先arr1替換,完事后arrN再替換)即支持多維替換
~~~
$arr=['a'=>1,'b'=>2,'c'=>3,4];
$arr1=['a'=>100];
$arrN=['d'=>5];
$ar=array_replace_recursive($arr,$arr1,$arrN);
array(5) {
["a"]=> int(100)
["b"]=>int(2)
["c"]=>int(3)
[0]=>int(4)
["d"]=>int(5)
}
~~~
### **array_replace**($arr ,$arr1,$arrN )? ?(用法同**array_replace_recursive**)一維?數組替換 不能遞歸替換
## **數組元素查找**
### **array_search**($search_value,?`$arr`,?false ); 一維數組中查找指定元素 返回鍵名 (只返回匹配的第一個)
### **array_keys**($arr?,?`$search_value=null,false`?);//返回一維數組元素值相同的所有鍵名
### **array_keys**($arr);//返回一維數組的所有鍵名
~~~
$array = array(0 => 'blue', 1 => 'red', 2 => 'green', 3 => 'red',4=>"green");
$key = array_search('green', $array); // $key = 2;
$keys=array_keys($array,'green');//[2,4]
~~~
### **array_values**($arr);? ? 返回數組中所有的值?
### **in_array**($search_value, $arr, FALSE【嚴格匹配】);? ?檢查一維數組里是否存在給定的值? ?
### [array_key_exists()](https://www.php.net/manual/zh/function.array-key-exists.php)?- 檢查數組一維里是否有指定的鍵名或索引(返回bolean)?
## **求和**
## **array_sum**()? 返回一維數組所有的值總和
## **數組去重**
### **array_unique($arr)**
### **array_flip**(array_flip($arr)); 這樣便可以刪除重復元素。 比上面的要效率;
原理:array_flip()交換數組中的鍵和值但是php鍵是唯一的而且數組中可以有相同的值如果交換鍵和值的話最后一個相同的值或取代前面相同的值進行交換
## **關聯數組變索引數組:**
### **array_values($arr)** 返回含所有值的索引數組
## **php數組差集交集并集**
### **差集:(取獨有)**? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 返回arr中有某個值而其他它arr1~arrN無此值或鍵或鍵值的結果
array\_?diff\_?key? ? ? ? ? ? ? ? ? ? ? ? 計算差集(系統函數比較鍵)
array\_?diff? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 計算差集(系統函數比較值)
array\_?diff\_?assoc? ? ? ? ? ? ? ? ? ? ?計算差集(系統函數比較鍵和值)
array\_?diff\_?uassoc? ? ? ? ? ? ? ? ? ?計算差集(系統函數比較值,自定義函數比較鍵)
array\_?diff\_?ukey? ? ? ? ? ? ? ? ? ? ? ?計算差集(自定義函數比較鍵)要么全是關聯數組要么全是索引數組
array\_?udiff\_?assoc? ? ? ? ? ? ? ? ? ?計算差集(系統函數比較鍵,自定義函數比較值)
array\_?udiff\_?uassoc? ? ? ? ? ? ? ? ?計算差集(自定義函數比較值和鍵)
array\_?udiff? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?計算差集(自定義函數比較值)
### **交集(取共同)**? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 返回arr中有某個值且其他它arr1~arrN也有此鍵或值或鍵值的結果
array\_?intersect\_?key? ? ? ? ? ? ? ? ?計算交集(系統函數比較鍵)
array\_?intersect? ? ? ? ? ? ? ? ? ? ? ? 計算交集(系統函數比較值)
array\_?intersect\_?assoc? ? ? ? ? ? ?計算交集(系統函數比較鍵和值)
array\_?intersect\_?uassoc? ? ? ? ? ?計算交集(系統函數比較鍵和值)
array\_?intersect\_?ukey? ? ? ? ? ? ? ?計算交集(系統函數比較值,自定義函數比較鍵)
array\_?uintersect\_?assoc? ? ? ? ? ?計算交集(系統函數比較鍵,自定義函數比較值)
array\_?uintersect\_?uassoc? ? ? ? ?計算交集(自定義函數比較值和鍵)
array\_?uintersect? ? ? ? ? ? ? ? ? ? ? 計算交集(自定義函數比較值)
### **并集**(取全部)
array\_merge($arr1,$arrN);
array\_merge\_recursive ($array1 ,$arrN); //有相同字符串的key則合并,其余追加(鍵值相同不覆蓋)
## **數組循環比較**
一般加引用要慢點
foreach 與array\_walk相比?array\_walk多出一個函數調用
效率 for≈foreach(無key) >foreach(有key)>foreach(有key+引用)>foreach(無key+引用)>array\_walk(函數在外) >array\_walk(函數在內)?>array\_walk(引用)?>array\_map
~~~
foreach是最快的,因為php的array內部元素之間有指針,就是list,直接指向下個元素的內存地址,所以遍歷速度很快
for的問題在于,每次都要做一個hash table的查詢。
array_walk/array_map 遍歷的方式和foreach一樣的,慢是慢在回調函數
~~~
?但是如果在循環里有函數調用array\_walk的效率是最高的、
~~~
$max = 1000000;
$test_arr = range(0, $max);
$temp=0;
echo "<br>";
echo "<br>";
echo "<br>";
/*for 的方法*/
$t1 = microtime(true);
for ($i = 0; $i < $max; $i++) {
demo($i);
}
$t2 = microtime(true);
$t = $t2 - $t1;
echo "就使用for, 花費: {$t}<br>\n";
/*foreach*/
$t1 = microtime(true);
foreach ($test_arr as $key => $value) {
demo($value);
}
$t2 = microtime(true);
$t = $t2 - $t1;
echo "就使用foreach有key, 花費: {$t}<br>\n";
/*foreach*/
$t1 = microtime(true);
foreach ($test_arr as $value) {
demo($value);
}
$t2 = microtime(true);
$t = $t2 - $t1;
echo "就使用foreach無key, 花費: {$t}<br>\n";
/*foreach*/
$t1 = microtime(true);
foreach ($test_arr as &$value) {
demo($value);
}
$t2 = microtime(true);
$t = $t2 - $t1;
echo "就使用foreach無key+引用, 花費: {$t}<br>\n";
/*foreach*/
$t1 = microtime(true);
foreach ($test_arr as $key => &$value) {
demo($value);
}
$t2 = microtime(true);
$t = $t2 - $t1;
echo "就使用foreach有key+引用, 花費: {$t}<br>\n";
/*array_walk*/
$t1 = microtime(true);
array_walk($test_arr ,function(&$itemValue,$key){
demo($itemValue);
});
$t2 = microtime(true);
$t = $t2 - $t1;
echo "array_walk+引用, 花費: {$t}<br>\n";
/*array_walk*/
$t1 = microtime(true);
array_walk($test_arr ,function($itemValue,$key){
demo($itemValue);
});
$t2 = microtime(true);
$t = $t2 - $t1;
echo "array_walk, 花費: {$t}<br>\n";
/*array_walk*/
$t1 = microtime(true);
array_walk($test_arr ,'arrayWalkCallBack');
$t2 = microtime(true);
$t = $t2 - $t1;
echo "array_walk 函數在外, 花費: {$t}<br>\n";
function demo($num)
{
$test=new stdClass();
$test->name='dash';
$test->age=28;
$test->like='乒乓';
$test->code=$num;
return $test;
}
function arrayWalkCallBack($itemValue,$key){
demo($itemValue);
}
~~~
### **array_map**
array_map的主要作用是通過自定義函數對數組的值進行另外處理,另外可以做為對多個數組的相對應單元進行數據合并處理等。
* 1,array_map在調用的方法中取不到數組的鍵名,特別是只傳遞一個數組的時候,它完全是處理值。
* 2,只傳遞一個數組給array\_map最后得到的數組鍵名不變,但是如果傳遞多個數組則鍵名全都自動變成重新排列的數字索引。
* 3,回調函數是平行作用于相應的單元上的, 所以使用多個數組時,它們的長度應該相同。不然則最短的一個將被用空的單元擴充。
~~~
$data =[
226495 => '2018-12-25 10:47:47',
226519 => '2018-12-25 10:47:45',
226499 => '2018-12-25 10:47:44',
226604 => '2019-01-11 11:21:51',
226517 => '2018-12-25 10:47:36',
226630 => '2019-01-11 11:17:56',
226493 => '2018-12-25 10:47:34',
226502 => '2018-12-25 10:47:32',
];
$datas =[
1=>'2018-12-25 10:47:47',
2=>'2018-12-25 10:47:45',
3=>'2018-12-25 10:47:44',
4=>'2019-01-11 11:21:51',
4=>'2018-12-25 10:47:36',
6=>'2019-01-11 11:17:56',
7=>'2018-12-25 10:47:34',
8=>'2018-12-25 10:47:32',
];
//調用array_map對單個數組值進行處理,索引能保持
$res1=array_map(function($val){
//只獲取時分秒
return explode(' ', $val)[1];
}, $data);
var_export($res1);
/*
array (
226495 => '10:47:47',
226519 => '10:47:45',
226499 => '10:47:44',
226604 => '11:21:51',
226517 => '10:47:36',
226630 => '11:17:56',
226493 => '10:47:34',
226502 => '10:47:32',
)
*/
//傳遞多個數組后返回的數組鍵名重新進行數字索引
$res2=array_map(function($value,$value2){
//只獲年月日
return current(explode(' ', $value));
}, $data, $datas);
var_export($res2);
/*
array (
0 => '2018-12-25',
1 => '2018-12-25',
2 => '2018-12-25',
3 => '2019-01-11',
4 => '2018-12-25',
5 => '2019-01-11',
6 => '2018-12-25',
7 => '2018-12-25',
)
*/
//傳遞多個數組進行數據重組處理
$res3=array_map(function($value,$value2){
return explode(' ', $value)[1].'=='.$value2;
}, $data, $datas);
var_export($res3);
/**數據怎么錯亂了??
array (
0 => '10:47:47==2018-12-25 10:47:47',
1 => '10:47:45==2018-12-25 10:47:45',
2 => '10:47:44==2018-12-25 10:47:44',
3 => '11:21:51==2018-12-25 10:47:36',
4 => '10:47:36==2019-01-11 11:17:56',
5 => '11:17:56==2018-12-25 10:47:34',
6 => '10:47:34==2018-12-25 10:47:32',
7 => '10:47:32==',
)
/
~~~
實戰:三個維度的數據合并
```
//三個維度的數據合并
$names = array('zhangsan', 'lisi', 'wangwu');
$sex = array("man", "sex", "man");
$age = array(20, 25, 28);
$users = array_map(null, $names, $sex, $age);
print_r($users);
//輸出結果如下:
Array
(
[0] => Array
(
[0] => zhangsan
[1] => 20
[2] => man
)
[1] => Array
(
[0] => lisi
[1] => 25
[2] => sex
)
[2] => Array
(
[0] => wangwu
[1] => 28
[2] => man
)
)
```
### [**array_walk**()](https://www.php.net/manual/zh/function.array-walk.php)( array &$array , callable $funcname [, mixed $userdata = NULL ] ) - 使用用戶自定義函數對數組中的每個元素做回調處理
1, array\_walk同時能拿到數據的鍵和值
2,array\_walk并不返回新數組,只返回標識操作是否成功的布爾值
3,因為array\_walk不返回數組,array\_walk的使用更傾向于在原數組上進行數據修改處理,當然也可以在另外一個變量上處理。
```
$names = array(1=>'zhangsan',2=> 'lisi',3=> 'wangwu');
//不修改原數組,直接顯示
$result = array_walk($names, function($value, $key){
echo '第',$key,'名:',$value,'<br>';
});
var_dump($result);
/*
第1名:zhangsan
第2名:lisi
第3名:wangwu
bool(true)
*/
//地址引用,直接修改
$result2 = array_walk($names, function(&$value, $key){
$value = '第'.$key.'名:'.$value;
});
print_r($names);
var_dump($result2);
/*
Array
(
[1] => 第1名:zhangsan
[2] => 第2名:lisi
[3] => 第3名:wangwu
)
bool(true)
*/
//地址引用,直接修改, 附帶其它數據
$result3 = array_walk($names, function(&$value, $key, $extra){
$value = $extra .$value;
}, $extra="大家好,");
print_r($names);
var_dump($result3);
/*
Array
(
[1] => 大家好,第1名:zhangsan
[2] => 大家好,第2名:lisi
[3] => 大家好,第3名:wangwu
)
bool(true)
*/
```
**通過上面對array\_map和array\_walk的使用,綜合起來對比區別如下:**
**1,array\_walk主要是針對單個數組進行處理,array\_map可以處理單個,也可以把多個數組結合一起處理。**
**2,array\_map的作用更多的是得到一個新數組,array\_walk更多的是想做一些job, 只要結果執行成功了即行。**
**3,對單個數組進行操作時,array\_map和array\_walk功能很像,區別在于array\_map是取得返回的數組;而array\_walk因為不返回所以通過地址引用在原數組上修改以實現“返回”。**
**4,對多個數組處理時array\_map比array\_walk更適合。**
### [**array_?walk_?recursive**](https://www.php.net/manual/zh/function.array-walk-recursive.php "array_?walk_?recursive")($arr?,?`$callback`?\[,?[mixed](https://www.php.net/manual/zh/language.pseudo-types.php#language.types.mixed)?$userdata?=?NULL?])? 數組循環之遞歸的為每個數組元素調用callback
與array\_walk不同的是,array\_walk\_recursive函數會遞歸到更深層的數組中去,即對多維數組,array\_walk\_recursive會深入到更深層的數組鍵值中去處理。有一點需要要特別注意的是傳入給array\_walk\_recursive的數組參數中任何值為 array 的鍵都不會被傳遞到回調函數中去如:
```
$fruits = ['sweet' => ['a' => 'apple', 'b' => 'banana'], 'sour' => 'lemon'];
array_walk_recursive($fruits, function($item, $key){
echo "$key => $item\n";
});
/**注意上例中的鍵 'sweet' 并沒有顯示出來。任何其值為 array 的鍵都不會被傳遞到回調函數中去
就像這里sweet下標對應的值位數組,所以這里不會返回
a => apple
b => banana
sour => lemon
**/
```
**示例:多維變一維**
```
$array=[
1=>[2,5=>[4,2],[7,8=>[3,6]],5],
2=>4
];
var_export($array);
$arr=[];
array_walk_recursive($array, function($k){
global $arr;
$arr[]=$k;
});
print_r($arr);//Array ( [0] => 2 [1] => 4 [2] => 2 [3] => 7 [4] => 3 [5] => 6 [6] => 5 [7] => 4 )
```
**額外參數:**
```
$fruits = ['sweet' => ['a' => 'apple', 'b' => 'banana'], 'sour' => 'lemon'];
$extra1=1;
$extra2=2;
array_walk_recursive($fruits, function($item, $key, $extra){
echo "$key => $item\n $extra[0]<==>$extra[1]\n";
}, [$extra1,$extra2]);
```
**外部變量持久化**
```
$arr = [
'one' => ['one_one' => 'A', 'one_two' => 'B'],
'two' => 2
];
$counter = 0;
//默認情況下,外部變量在回調函數中保存不了的
array_walk_recursive( $arr, function($value, $key, $counter) {
$counter++;
echo $value." :". $counter";
}, $counter);
echo "counter :". $counter;
/** 結果:
A : 1
B : 1
2 : 1
counter : 0
**/
//僅在相同的數組節點中持久存在使用引用
array_walk_recursive( $arr, function($value, $key, &$counter) {
$counter++;
echo $value." :". $counter";
}, $counter);
echo "counter :". $counter;
/** 結果:
A : 1
B : 2
2 : 1
counter : 0
**/
//完全持久的化使用"use"關鍵字
array_walk_recursive( $arr, function($value, $key) use (&$counter) {
$counter++;
echo $value." :". $counter";
}, $counter);
echo "counter :". $counter;
/** 結果:
A : 1
B : 2
2 : 3
counter : 3
**/
```
## 所有鍵名轉小寫或者大寫
### array_?change_?key_?case($arr , CASE_LOWER | CASE_UPPER):
## [返回指定【下標】的值組成的新數組(返回的值還可以指定下標)](https://www.php.net/manual/zh/function.array-column.php "array_?column")
[array\_?column($arr, $key=null ,$newArrKey=null);//返回指定【下標key】的值組成的新數組(第三個參數指定返回值的下標)](https://www.php.net/manual/zh/function.array-column.php "array_?column")
```
array_column ($arr, null ,null);//返回指定【下標】的值(返回的值還可以指定下標)
/*
$arr=[
[
'id' => 21,
'first_name' => 'John',
'last_name' => 'Doe',
],
[
'id' => 35,
'first_name' => 'John',
'last_name' => 'Doe',
[
'id'=>'50'
]
]
]
array_column($records, 'first_name',null);
$arr=[
[John,Peter]
];
array_column($records, 'first_name','id');
$arr=[
[21=>John,35=>Peter]
];
array_column($records, null,'id');
$arr=[
21=>[
'id' => 21,
'first_name' => 'John',
'last_name' => 'Doe',
],
35=>[
'id' => 35,
'first_name' => 'John',
'last_name' => 'Doe',
[
'id'=>'50'
]
]
]
*/
```
## [array\_?count\_?values](https://www.php.net/manual/zh/function.array-count-values.php "array_?count_?values")($arr)? ?計算數組中每個值出現的次數 返回原數組的值為鍵 出現次數為值的數組
## [array\_?fill\_?keys($keysArr, $mixed\_value);](https://www.php.net/manual/zh/function.array-fill-keys.php "array_?fill_?keys")? 用戶指定鍵和值來填充數組
~~~
$keys = array('foo', 5, 10, 'bar');//第一個參數數組的值作為填充數組的鍵,第二個參數作為值
array_fill_keys($keys, 'banana'); //['foo'=>'banana',5=>'banana',10=>'banana','bar'=>'banana']
$keys = array('foo', 5);
$value=array('banana','apple');
$a=array_fill_keys($keys,$value);
//['foo'=>['banana','apple'],5=>['banana','apple']]
~~~
## [array\_?fill](https://www.php.net/manual/zh/function.array-fill.php "array_?fill")($start\_index , $num(超過這個給定數組的長度就不填充了) ,$mixed\_value);給定的值填充數組
[array\_?flip](https://www.php.net/manual/zh/function.array-flip.php "array_?flip")
[array\_?intersect\_?assoc](https://www.php.net/manual/zh/function.array-intersect-assoc.php "array_?intersect_?assoc")
[array\_?intersect\_?key](https://www.php.net/manual/zh/function.array-intersect-key.php "array_?intersect_?key")
[array\_?intersect\_?uassoc](https://www.php.net/manual/zh/function.array-intersect-uassoc.php "array_?intersect_?uassoc")
[array\_?intersect\_?ukey](https://www.php.net/manual/zh/function.array-intersect-ukey.php "array_?intersect_?ukey")
[array\_?intersect](https://www.php.net/manual/zh/function.array-intersect.php "array_?intersect")
[array\_?key\_?exists](https://www.php.net/manual/zh/function.array-key-exists.php "array_?key_?exists")
[array\_?key\_?first](https://www.php.net/manual/zh/function.array-key-first.php "array_?key_?first")
[array\_?key\_?last](https://www.php.net/manual/zh/function.array-key-last.php "array_?key_?last")
[array\_?keys](https://www.php.net/manual/zh/function.array-keys.php "array_?keys")
[array\_?map](https://www.php.net/manual/zh/function.array-map.php "array_?map")
[array\_?merge\_?recursive](https://www.php.net/manual/zh/function.array-merge-recursive.php "array_?merge_?recursive")
[array\_?merge](https://www.php.net/manual/zh/function.array-merge.php "array_?merge")
[array\_?pad](https://www.php.net/manual/zh/function.array-pad.php "array_?pad")
[array\_?pop](https://www.php.net/manual/zh/function.array-pop.php "array_?pop")
[array\_?product](https://www.php.net/manual/zh/function.array-product.php "array_?product")
[array\_?push](https://www.php.net/manual/zh/function.array-push.php "array_?push")
[array\_?rand](https://www.php.net/manual/zh/function.array-rand.php "array_?rand")
[array\_?reduce](https://www.php.net/manual/zh/function.array-reduce.php "array_?reduce")
[array\_?replace\_?recursive](https://www.php.net/manual/zh/function.array-replace-recursive.php "array_?replace_?recursive")
[array\_?replace](https://www.php.net/manual/zh/function.array-replace.php "array_?replace")
[array\_?reverse](https://www.php.net/manual/zh/function.array-reverse.php "array_?reverse")
[array\_?search](https://www.php.net/manual/zh/function.array-search.php "array_?search")
[array\_?shift](https://www.php.net/manual/zh/function.array-shift.php "array_?shift")
[array\_?slice](https://www.php.net/manual/zh/function.array-slice.php "array_?slice")
[array\_?splice](https://www.php.net/manual/zh/function.array-splice.php "array_?splice")
[array\_?sum](https://www.php.net/manual/zh/function.array-sum.php "array_?sum")
[array\_?udiff\_?assoc](https://www.php.net/manual/zh/function.array-udiff-assoc.php "array_?udiff_?assoc")
[array\_?udiff\_?uassoc](https://www.php.net/manual/zh/function.array-udiff-uassoc.php "array_?udiff_?uassoc")
[array\_?udiff](https://www.php.net/manual/zh/function.array-udiff.php "array_?udiff")
[array\_?uintersect\_?assoc](https://www.php.net/manual/zh/function.array-uintersect-assoc.php "array_?uintersect_?assoc")
[array\_?uintersect\_?uassoc](https://www.php.net/manual/zh/function.array-uintersect-uassoc.php "array_?uintersect_?uassoc")
[array\_?uintersect](https://www.php.net/manual/zh/function.array-uintersect.php "array_?uintersect")
[array\_?unique](https://www.php.net/manual/zh/function.array-unique.php "array_?unique")
[array\_?unshift](https://www.php.net/manual/zh/function.array-unshift.php "array_?unshift")
[array\_?values](https://www.php.net/manual/zh/function.array-values.php "array_?values")
[array\_?walk\_?recursive](https://www.php.net/manual/zh/function.array-walk-recursive.php "array_?walk_?recursive")
[array\_?walk](https://www.php.net/manual/zh/function.array-walk.php "array_?walk")
[array](https://www.php.net/manual/zh/function.array.php "array")
[arsort](https://www.php.net/manual/zh/function.arsort.php "arsort")
[asort](https://www.php.net/manual/zh/function.asort.php "asort")
[compact](https://www.php.net/manual/zh/function.compact.php "compact")
[count](https://www.php.net/manual/zh/function.count.php "count")
[current](https://www.php.net/manual/zh/function.current.php "current")
[end](https://www.php.net/manual/zh/function.end.php "end")
[extract](https://www.php.net/manual/zh/function.extract.php "extract")
[in\_?array](https://www.php.net/manual/zh/function.in-array.php "in_?array")
[key\_?exists](https://www.php.net/manual/zh/function.key-exists.php "key_?exists")
[key](https://www.php.net/manual/zh/function.key.php "key")
[krsort](https://www.php.net/manual/zh/function.krsort.php "krsort")
[ksort](https://www.php.net/manual/zh/function.ksort.php "ksort")
[list](https://www.php.net/manual/zh/function.list.php "list")
[natcasesort](https://www.php.net/manual/zh/function.natcasesort.php "natcasesort")
[natsort](https://www.php.net/manual/zh/function.natsort.php "natsort")
[next](https://www.php.net/manual/zh/function.next.php "next")
[pos](https://www.php.net/manual/zh/function.pos.php "pos")
[prev](https://www.php.net/manual/zh/function.prev.php "prev")
[range](https://www.php.net/manual/zh/function.range.php "range")
[reset](https://www.php.net/manual/zh/function.reset.php "reset")
[rsort](https://www.php.net/manual/zh/function.rsort.php "rsort")
[shuffle](https://www.php.net/manual/zh/function.shuffle.php "shuffle")
[sizeof](https://www.php.net/manual/zh/function.sizeof.php "sizeof")
[sort](https://www.php.net/manual/zh/function.sort.php "sort")
[uasort](https://www.php.net/manual/zh/function.uasort.php "uasort")
[uksort](https://www.php.net/manual/zh/function.uksort.php "uksort")
[usort](https://www.php.net/manual/zh/function.usort.php "usort")
Deprecated
[each](https://www.php.net/manual/zh/function.each.php "each")
檢測方法是否存在:method\_exists()
檢測方法是否存在且(外部)可調用:is\_callable()
~~~
class Test {
public function PublicMethod(){}
protected function ProtectedMethod(){}
private function PrivateMethod(){}
public static function PublicStaticMethod(){}
protected static function ProtectedStaticMethod(){}
private static function PrivateStaticMethod(){}
}
$test = new Test();
$callbacks = array(
array($test, 'PublicMethod'),//true
array($test, 'ProtectedMethod'),//false
array($test, 'PrivateMethod'),//false
array($test, 'PublicStaticMethod'),//true
array($test, 'ProtectedStaticMethod'),//false
array($test, 'PrivateStaticMethod'),//false
array('Test', 'PublicMethod'),//true
array('Test', 'ProtectedMethod'),//false
array('Test', 'PrivateMethod'),//false
array('Test', 'PublicStaticMethod'),//true
array('Test', 'ProtectedStaticMethod'),//false
array('Test', 'PrivateStaticMethod'),//false
);
foreach ($callbacks as $callback){
//var_dump($callback);
echo'is_callable:'; var_dump(is_callable($callback));
}
class Test {
public function PublicMethod(){}
protected function ProtectedMethod(){}
private function PrivateMethod(){}
public static function PublicStaticMethod(){}
protected static function ProtectedStaticMethod(){}
private static function PrivateStaticMethod(){}
}
$test = new Test();
$callbacks = array(
array($test, 'PublicMethod'),//true
array($test, 'ProtectedMethod'),//true
array($test, 'PrivateMethod'),//true
array($test, 'PublicStaticMethod'),//true
array($test, 'ProtectedStaticMethod'),//true
array($test, 'PrivateStaticMethod'),//true
array('Test', 'PublicMethod'),//true
array('Test', 'ProtectedMethod'),//true
array('Test', 'PrivateMethod'),//true
array('Test', 'PublicStaticMethod'),//true
array('Test', 'ProtectedStaticMethod'),//true
array('Test', 'PrivateStaticMethod'),//true
);
foreach ($callbacks as $callback){
//var_dump($callback);
echo'method_exists:'; var_dump(method_exists($callback[0], $callback[1]));
}
~~~
類或對象的相關函數
[\_?\_?autoload](https://www.php.net/manual/zh/function.autoload.php "_?_?autoload")
[class\_?alias](https://www.php.net/manual/zh/function.class-alias.php "class_?alias")
[class\_?exists](https://www.php.net/manual/zh/function.class-exists.php "class_?exists")
[get\_?called\_?class](https://www.php.net/manual/zh/function.get-called-class.php "get_?called_?class")
[get\_?class\_?methods](https://www.php.net/manual/zh/function.get-class-methods.php "get_?class_?methods")
[get\_?class\_?vars](https://www.php.net/manual/zh/function.get-class-vars.php "get_?class_?vars")
[get\_?class](https://www.php.net/manual/zh/function.get-class.php "get_?class")
[get\_?declared\_?classes](https://www.php.net/manual/zh/function.get-declared-classes.php "get_?declared_?classes")
[get\_?declared\_?interfaces](https://www.php.net/manual/zh/function.get-declared-interfaces.php "get_?declared_?interfaces")
[get\_?declared\_?traits](https://www.php.net/manual/zh/function.get-declared-traits.php "get_?declared_?traits")
[get\_?object\_?vars](https://www.php.net/manual/zh/function.get-object-vars.php "get_?object_?vars")
[get\_?parent\_?class](https://www.php.net/manual/zh/function.get-parent-class.php "get_?parent_?class")
[interface\_?exists](https://www.php.net/manual/zh/function.interface-exists.php "interface_?exists")
[is\_?a](https://www.php.net/manual/zh/function.is-a.php "is_?a")
[is\_?subclass\_?of](https://www.php.net/manual/zh/function.is-subclass-of.php "is_?subclass_?of")
[method\_?exists( $className\_str|`$object`? ,`$methodName_str`?)](https://www.php.net/manual/zh/function.method-exists.php "method_?exists")? ?檢查類的方法是否存在
[property\_?exists](https://www.php.net/manual/zh/function.property-exists.php "property_?exists")
[trait\_?exists](https://www.php.net/manual/zh/function.trait-exists.php "trait_?exists")
Deprecated
[call\_?user\_?method\_?array](https://www.php.net/manual/zh/function.call-user-method-array.php "call_?user_?method_?array")
[call\_?user\_?method](https://www.php.net/manual/zh/function.call-user-method.php "call_?user_?method")
**為什么我在點擊瀏覽器的后退按鈕后,所有字段的信息都被清空了?**
提交表單的頁面使用了session\_start();該函數會強制當前頁面不被緩存,表單提交錯誤數據時后在返回提交頁面表單使內容被清空,要想保留表單的數據怎么辦?
第一種方法:使用session\_cache\_limiter('private, must-revalidate')函數,但是要值得注意的是session\_cache\_limiter()方法要寫在session\_start()方法之前才有用;
第二種方法:header('Cache-control: private, must-revalidate');//支持頁面回跳;在session\_start()方法之后用
\_\_DIR\_\_和dirname(\_\_FILE\_\_);都是獲取當前腳本所在目錄的\_\_DIR\_\_效率高但是實在php5.3加入的所以用時需要注意
- php更新內容
- PHP PSR 標準規范
- 輔助查詢(*)
- composer項目的創建
- composer安裝及設置
- composer自動加載講解
- phpsdudy的composer操作
- git
- Git代碼同時上傳到GitHub和Gitee(碼云)
- Git - 多人協同開發利器,團隊協作流程規范與注意事項
- 刪除遠程倉庫的文件
- github查詢方法
- 錯誤
- 其他
- php.ini
- php配置可修改范圍
- php超時
- 防跨目錄設置
- 函數可變參數
- 【時間】操作
- 時間函數例子
- Date/Time 函數(不包含別名函數)
- DateTime類別名函數
- 【數字】操作
- 【字符串】操作
- 【數組】操作
- 排序
- 合并案例
- empty、isset、is_null
- echo 輸出bool值
- if真假情況
- 流程控制代替語法【if (條件): endif;】
- 三元運算
- 運算符優先級
- 常量
- define與const(php5.3) 類常量
- 遞歸
- 單元測試
- 面向對象
- 對象(object) 與 數組(array) 的轉換
- php網絡相關
- 支持的協議和封裝協議(如http,php://input)
- php://協議
- file://協議
- http(s)://協議
- ftp(s)://協議
- zip://, bzip2://, zlib://協議
- data://協議
- glob://協議
- expect://協議
- phar://
- ssh2
- rar://
- ogg://
- 上下文(Context)選項和參數
- 過濾器
- http請求及模擬登錄
- 常用的header頭部定義匯總
- HTTP響應頭和請求頭信息對照表
- HTTP請求的返回值含義說明
- content-type對照表
- Cache-Control對照
- curl函數
- 防止頁面刷新
- telnet模擬get、post請求
- 三種方式模擬表單發布留言
- 模擬登陸
- 防盜鏈
- php+mysql模擬隊列發送郵件
- socket
- 使用websocket實現php消息實時推送完整示例
- streams
- Stream函數實現websocket
- swoole
- 網絡編程基本概念
- 全局變量域超全局變量
- 超全局變量
- $_ENV :存儲了一些系統的環境變量
- $_COOKIE
- $_SESSION
- $_FILES
- $_SERVER
- 正則
- php正則函數
- 去除文本中的html、xml的標簽
- 特殊符號
- \r\n
- 模式修正符
- 分組
- 斷言(環視?)
- 條件表達式
- 遞歸表達式 (?R)
- 固化分組
- 正則例子
- 提取類文件的公共方法
- 抓取網頁內容
- 匹配中文字符
- 提取sql日志文件
- 框架
- 文件操作
- 自動加載spl_autoload_register
- 文件加載
- 文件的上傳下載
- 常見的mimi類型
- 文件斷點續傳
- 下載文件防盜鏈
- 破解防盜鏈
- 將字節轉為人可讀的單位
- 無限分類
- 短信驗證碼
- 短信寶
- 視頻分段加載
- 隱藏地址
- MPEG DASH視頻分片技術
- phpDoc注釋
- @錯誤抑制符
- 字符編碼
- PHP CLI模式開發
- CGI、FastCGI和PHP-FPM關系圖解
- No input file specified的解決方法
- SAPI(PHP常見的四種運行模式)
- assert斷言
- 輪詢(Event Loop)
- 異常處理
- 異常分類
- php系統異常
- 錯誤級別
- set_error_handler
- set_exception_handler
- register_shutdown_function
- try catch
- tp5異常處理類解析
- 文件上傳相關設置
- 進程/線程/協程
- 協程
- 什么是協程
- 引用&
- Heredoc和Nowdoc語法
- 類基礎
- 系統預定義類
- pdo
- 類的三大特性:封裝,繼承,多態
- 魔術方法
- extends繼承
- abstract 抽象類
- interface 接口(需要implements實現)
- 抽象類和接口的區別
- 多態
- static
- final
- serialize與unserialize
- instanceof 判斷后代子類
- 類型約束
- clone克隆
- ::的用法
- static::class、self::class
- new self()與new static()
- this、self、static、parent、super
- self、static、parent:后期靜態綁定
- PHP的靜態變量
- php導入
- trait
- 動態調用類方法
- 參數及類型申明
- 方法的重載覆蓋
- return $a && $b
- 類型聲明
- 設計思想
- 依賴注入與依賴倒置
- MVC模式與模板引擎
- 模版引擎
- smarty模版
- 系統變量、全局變量
- 語言切換
- 函數-給函數默認值
- 流程控制-遍歷
- 模版加載
- 模版繼承
- blade
- twig
- Plates
- 創建型模式(創建類對象)--單原二廠建
- (*)單例模式(保證一個類僅有一個實例)
- (*)工廠模式(自動實例化想要的類)
- 原型模式(在指定方法里克隆this)
- 創建者模式(建造者類組裝近似類屬性)
- 結構型模式 --橋(幫)組享外帶裝適
- 適配器模式(Adapter 用于接口兼容)
- 橋接模式(方法相同的不同類之間的快速切換)
- 裝飾模式(動態增加類對象的功能 如游戲角色的裝備)
- 組合模式(用于生成類似DOMDocument這種節點類)
- 外觀模式(門面(Facade)模式 不同類的統一調用)
- 享元模式
- 代理模式
- 行為型模式--觀摩職命狀-備爹在房中潔廁
- (*)觀察者模式
- (*)迭代器模式(Iterator)
- 模板方法模式 Template
- 命令模式(Command)
- 中介者模式(Mediator)
- 狀態模式(State)
- 職責鏈模式 (Chainof Responsibility)
- 策略模式(Strategy)
- 已知模式-備忘錄模式(Memento)
- 深度模式-解釋器模式(Interpreter)
- 深度模式-訪問者模式(Visitor)
- (*)注冊樹(注射器、注冊表)模式
- PHP擴展庫列表
- 函數參考
- 影響 PHP 行為的擴展
- APC擴展(過時)
- APCu擴展
- APD擴展(過時)
- bcompiler擴展(過時)
- BLENC擴展 (代碼加密 實驗型)
- Componere擴展(7.1+)
- Componere\Definition
- Componere\Patch
- Componere \ Method
- Componere\Value
- Componere函數
- 錯誤處理擴展(PHP 核心)
- FFI擴展
- 基本FFI用法
- FFI api
- htscanner擴展
- inclued擴展
- Memtrack擴展
- OPcache擴展(5.5.0內部集成)
- Output Control擴展(核心)
- PHP Options/Info擴展(核心)
- 選項、 信息函數
- phpdbg擴展(5.6+內部集成)
- runkit擴展
- runkit7擴展
- scream擴展
- uopz擴展
- Weakref擴展
- WeakRef
- WeakMap
- WinCache擴展
- Xhprof擴展
- Yac(7.0+)
- 音頻格式操作
- ID3
- KTaglib
- oggvorbis
- OpenAL
- 身份認證服務
- KADM5
- Radius
- 針對命令行的擴展
- Ncurses(暫無人維護)
- Newt(暫無人維護)
- Readline
- 壓縮與歸檔擴展
- Bzip2
- LZF
- Phar
- Rar
- Zip
- Zlib
- 信用卡處理
- 加密擴展
- Crack(停止維護)
- CSPRNG(核心)
- Hash擴展(4.2內置默認開啟、7.4核心)
- Mcrypt(7.2移除)
- Mhash(過時)
- OpenSSL(*)
- 密碼散列算法(核心)
- Sodium(+)
- 數據庫擴展
- 數據庫抽象層
- DBA
- dbx
- ODBC
- PDO(*)
- 針對各數據庫系統對應的擴展
- CUBRID
- DB++(實驗性)
- dBase
- filePro
- Firebird/InterBase
- FrontBase
- IBM DB2
- Informix
- Ingres
- MaxDB
- Mongo(MongoDB老版本)
- MongoDB
- mSQL
- Mssql
- MySQL
- OCI8(Oracle OCI8)
- Paradox
- PostgreSQL
- SQLite
- SQLite3
- SQLSRV(SQL Server)
- Sybase
- tokyo_tyrant
- 日期與時間相關擴展
- Calendar
- 日期/時間(核心)
- HRTime(*)
- 文件系統相關擴展
- Direct IO
- 目錄(核心)
- Fileinfo(內置)
- 文件系統(核心)
- Inotify
- Mimetype(過時)
- Phdfs
- Proctitle
- xattr
- xdiff
- 國際化與字符編碼支持
- Enchant
- FriBiDi
- Gender
- Gettext
- iconv(內置默認開啟)
- intl
- 多字節字符串(mbstring)
- Pspell
- Recode(將要過時)
- 圖像生成和處理
- Cairo
- Exif
- GD(內置)
- Gmagick
- ImageMagick
- 郵件相關擴展
- Cyrus
- IMAP
- Mail(核心)
- Mailparse
- vpopmail(實驗性 )
- 數學擴展
- BC Math
- GMP
- Lapack
- Math(核心)
- Statistics
- Trader
- 非文本內容的 MIME 輸出
- FDF
- GnuPG
- haru(實驗性)
- Ming(實驗性)
- wkhtmltox(*)
- PS
- RPM Reader(停止維護)
- RpmInfo
- XLSWriter Excel操作(*)
- php第三方庫非擴展
- 進程控制擴展
- Eio
- Ev
- Expect
- Libevent
- PCNTL
- POSIX
- 程序執行擴展(核心)
- parallel
- pthreads(*)
- pht
- Semaphore
- Shared Memory
- Sync
- 其它基本擴展
- FANN
- GeoIP(*)
- JSON(內置)
- Judy
- Lua
- LuaSandbox
- Misc(核心)
- Parsekit
- SeasLog(-)
- SPL(核心)
- SPL Types(實驗性)
- Streams(核心)
- stream_wrapper_register
- stream_register_wrapper(同上別名)
- stream_context_create
- stream_socket_client
- stream_socket_server
- stream_socket_accept
- stream_socket_recvfrom
- stream_socket_sendto
- Swoole(*)
- Tidy擴展
- Tokenizer
- URLs(核心)
- V8js(*)
- Yaml
- Yaf
- Yaconf(核心)
- Taint(檢測xss字符串等)
- Data Structures
- Igbinary(7.0+)
- 其它服務
- 網絡(核心)
- Sockets
- socket_create
- socket_bind(服務端即用于監聽的套接字)
- socket_listen(服務端)
- socket_accept(服務端)
- socket_connect(客戶端)
- socket_read
- socket_recv(類似socket_read)
- socket_write
- socket_send
- socket_close
- socket_select
- socket_getpeername
- socket_getsockname
- socket_get_option
- socket_getopt(socket_get_option的別名)
- socket_set_option
- socket_setopt( socket_set_option的別名)
- socket_recvfrom
- socket_sendto
- socket_addrinfo_bind
- socket_addrinfo_connect
- socket_addrinfo_explain
- socket_addrinfo_lookup
- socket_clear_error
- socket_last_error
- socket_strerror
- socket_cmsg_space
- socket_create_listen
- socket_create_pair
- socket_export_stream
- socket_import_stream
- socket_recvmsg
- socket_sendmsg
- socket_set_block
- socket_set_nonblock
- socket_shutdown
- socket_wsaprotocol_info_export
- socket_wsaprotocol_info_import
- socket_wsaprotocol_info_release
- cURL(*)
- curl_setopt
- Event(*)
- chdb
- FAM
- FTP
- Gearman
- Gopher
- Gupnp
- Hyperwave API(過時)
- LDAP(+)
- Memcache
- Memcached(+)
- mqseries
- RRD
- SAM
- ScoutAPM
- SNMP
- SSH2
- Stomp
- SVM
- SVN(試驗性的)
- TCP擴展
- Varnish
- YAZ
- YP/NIS
- 0MQ(ZeroMQ、ZMQ)消息系統
- 0mq例子
- ZooKeeper
- 搜索引擎擴展
- mnoGoSearch
- Solr
- Sphinx
- Swish(實驗性)
- 針對服務器的擴展
- Apache
- FastCGI 進程管理器
- IIS
- NSAPI
- Session 擴展
- Msession
- Sessions
- Session PgSQL
- 文本處理
- BBCode
- CommonMark(markdown解析)
- cmark函數
- cmark類
- Parser
- CQL
- IVisitor接口
- Node基類與接口
- Document
- Heading(#)
- Paragraph
- BlockQuote
- BulletList
- OrderedList
- Item
- Text
- Strong
- Emphasis
- ThematicBreak
- SoftBreak
- LineBreak
- Code
- CodeBlock
- HTMLBlock
- HTMLInline
- Image
- Link
- CustomBlock
- CustomInline
- Parle
- 類函數
- PCRE( 核心)
- POSIX Regex
- ssdeep
- 字符串(核心)
- 變量與類型相關擴展
- 數組(核心)
- 類/對象(核心)
- Classkit(未維護)
- Ctype
- Filter擴展
- 過濾器函數
- 函數處理(核心)
- quickhash擴展
- 反射擴展(核心)
- Variable handling(核心)
- Web 服務
- OAuth
- api
- 例子:
- SCA(實驗性)
- SOAP
- Yar
- XML-RPC(實驗性)
- Windows 專用擴展
- COM
- 額外補充:Wscript
- win32service
- win32ps(停止更新且被移除)
- XML 操作(也可以是html)
- libxml(內置 默認開啟)
- DOM(內置,默認開啟)
- xml介紹
- 擴展類與函數
- DOMNode
- DOMDocument(最重要)
- DOMAttr
- DOMCharacterData
- DOMText(文本節點)
- DOMCdataSection
- DOMComment(節點注釋)
- DOMDocumentFragment
- DOMDocumentType
- DOMElement
- DOMEntity
- DOMEntityReference
- DOMNotation
- DOMProcessingInstruction
- DOMXPath
- DOMException
- DOMImplementation
- DOMNamedNodeMap
- DOMNodeList
- SimpleXML(內置,5.12+默認開啟)
- XMLReader(5.1+內置默認開啟 用于處理大型XML文檔)
- XMLWriter(5.1+內置默認開啟 處理大型XML文檔)
- SDO(停止維護)
- SDO-DAS-Relational(試驗性的)
- SDO DAS XML
- WDDX
- XMLDiff
- XML 解析器(Expat 解析器 默認開啟)
- XSL(內置)
- 圖形用戶界面(GUI) 擴展
- UI
- PHP SPL(PHP 標準庫)
- 數據結構
- SplDoublyLinkedList(雙向鏈表)
- SplStack(棧 先進后出)
- SplQueue(隊列)
- SplHeap(堆)
- SplMaxHeap(最大堆)
- SplMinHeap(最小堆)
- SplPriorityQueue(堆之優先隊列)
- SplFixedArray(陣列【數組】)
- SplObjectStorage(映射【對象存儲】)
- 迭代器
- ArrayIterator
- RecursiveArrayIterator(支持遞歸)
- DirectoryIterator類
- FilesystemIterator
- GlobIterator
- RecursiveDirectoryIterator
- EmptyIterator
- IteratorIterator
- AppendIterator
- CachingIterator
- RecursiveCachingIterator
- FilterIterator(遍歷并過濾出不想要的值)
- CallbackFilterIterator
- RecursiveCallbackFilterIterator
- RecursiveFilterIterator
- ParentIterator
- RegexIterator
- RecursiveRegexIterator
- InfiniteIterator
- LimitIterator
- NoRewindIterator
- MultipleIterator
- RecursiveIteratorIterator
- RecursiveTreeIterator
- 文件處理
- SplFileInfo
- SplFileObject
- SplTempFileObject
- 接口 interface
- Countable
- OuterIterator
- RecursiveIterator
- SeekableIterator
- 異常
- 各種類及接口
- SplSubject
- SplObserver
- ArrayObject(將數組作為對象操作)
- SPL 函數
- 預定義接口
- Traversable(遍歷)接口
- Iterator(迭代器)接口
- IteratorAggregate(聚合式迭代器)接口
- ArrayAccess(數組式訪問)接口
- Serializable 序列化接口
- JsonSerializable
- Closure 匿名函數(閉包)類
- Generator生成器類
- 生成器(php5.5+)
- yield
- 反射
- 一、反射(reflection)類
- 二、Reflector 接口
- ReflectionClass 類報告了一個類的有關信息。
- ReflectionObject 類報告了一個對象(object)的相關信息。
- ReflectionFunctionAbstract
- ReflectionMethod 類報告了一個方法的有關信息
- ReflectionFunction 類報告了一個函數的有關信息。
- ReflectionParameter 獲取函數或方法參數的相關信息
- ReflectionProperty 類報告了類的屬性的相關信息。
- ReflectionClassConstant類報告有關類常量的信息。
- ReflectionZendExtension 類返回Zend擴展相關信息
- ReflectionExtension 報告了一個擴展(extension)的有關信息。
- 三、ReflectionGenerator類用于獲取生成器的信息
- 四、ReflectionType 類用于獲取函數、類方法的參數或者返回值的類型。
- 五、反射的應用場景
- phpRedis
- API
- API詳細
- redis DB 概念:
- 通用命令:rawCommand
- Connection
- Server
- List
- Set
- Zset
- Hash
- string
- Keys
- 事物
- 發布訂閱
- 流streams
- Geocoding 地理位置
- lua腳本
- Introspection 自我檢測
- biMap
- 原生
- php-redis 操作類 封裝
- redis 隊列解決秒殺解決超賣:
- swoole+框架筆記
- 安裝及常用Cli操作
- TCP
- 4種回調函數的寫法
- easyswoole
- 目錄結構
- 配置文件
- Linux+Nginx
- 前置
- linux
- 開源網站鏡像及修改yum源
- 下載linux
- Liunx中安裝PHP7.4 的三種方法(Centos8)
- yum安裝
- 源碼編譯安裝
- LNMP一鍵安裝
- 查看linux版本號
- 設置全局環境變量
- 查看php.ini必須存放的位置
- 防火墻與端口開放
- nohup 后臺運行命令
- linux 查看nginx,php-fpm運行用戶及用戶組
- 網絡配置
- CentOS中執行yum update時報錯
- 關閉防火墻
- 查看端口是否被占用
- 查看文件夾大小
- nginx相關
- 一個典型的nginx配置
- nginx關于多個項目的配置(易于管理)
- nginx.config配置文件的結構
- 1、events
- 2、http
- nginx的location配置詳解
- Nginx相關命令
- Nginx安裝
- 配置偽靜態
- 為靜態配置例子
- apache
- nginx
- pathinfo模式
- Shell腳本
- bash
- shell 語言中 0 代表 true,0 以外的值代表 false。
- 變量
- shell字符串
- shell數組
- shell注釋
- 向Shell腳內傳遞參數
- 運算符
- 顯示命令執行結果
- printf
- test 命令
- 流程控制與循環
- if
- case
- for
- while
- until
- break和continue
- select 結構
- shell函數
- shell函數的全局變量和局部變量
- 將shell輸出寫入文件中(輸出重定向)
- Shell腳本中調用另一個Shell腳本的三種方式
- 定時任務
- PHP實現定時任務的五種方法
- 優化
- ab壓力測試
- 緩存
- opcache
- memcache
- php操作
- 數據庫
- 配置
- 數據庫鎖機制
- 主從分布
- 數據庫設計
- 邏輯設計
- 物理設計
- 字段類型的選擇
- 筆記
- SET FOREIGN_KEY_CHECKS
- 字符集與亂碼
- SQL插入 去除重復記錄的實現
- 分區表
- nginx 主從配置
- nginx 負載均衡的配置
- 手動搭建Redis集群和MySQL主從同步(非Docker)
- Redis Cluster集群
- mysql主從同步
- 用安卓手機搭建 web 服務器
- 軟件選擇
- url重寫
- 大流量高并發解決方案
- 權限設計
- ACL
- RBAC
- RBAC0
- RBAC1(角色上下級分層)
- RBAC2(用戶角色限約束)
- RBAC3
- 例子
- Rbac.class.php
- Rbac2
- Auth.class.php
- fastadmin Auth
- tree1
- ABAC 基于屬性的訪問控制
- 總結:SAAS后臺權限設計案例分析
- casbin-權限管理框架
- 開始使用
- casbinAPI
- casbin管理API
- RBAC API
- Think-Casbin
- 單點登錄(SSO)
- OAuth授權
- OAuth 2.0 的四種方式
- 授權碼
- 隱藏式
- 密碼式
- 憑證式
- 更新令牌
- 例子:第三方登錄
- 微服務架構下的統一身份認證和授權
- 代碼審計
- 漏洞挖掘的思路
- 命令注入
- 代碼注入
- XSS 反射型漏洞
- XSS 存儲型漏洞
- xss過濾
- HTML Purifier文檔
- 開始
- id規則
- class規則
- 過濾分類
- Attr
- AutoFormat
- CSS
- Cache
- Core
- Filter
- html
- Output
- Test
- URI
- 其他
- 嵌入YouTube視頻
- 加快HTML凈化器的速度
- 字符集
- 定制
- Tidy
- URI過濾器
- 在線測試
- xss例子
- 本地包含與遠程包含
- sql注入
- 函數
- 注釋
- 步驟
- information_schema
- sql注入的分類
- 實戰
- 防御
- CSRF 跨站請求偽造
- 計動態函數執行與匿名函數執行
- unserialize反序列化漏洞
- 覆蓋變量漏洞
- 文件管理漏洞
- 文件上傳漏洞
- 跳過登錄
- URL編碼對照表
- XXE
- 前端、移動端
- html5
- meta標簽
- flex布局
- javascript
- jquery
- 選擇器
- 精細分類
- 事件
- on事件無效:
- jquery自定義事件
- 表單操作
- 通用
- select
- checkbox
- radio
- js正則相關
- js中判斷某字符串含有某字符出現的次數
- js匹配指定字符
- $.getjson方法配合在url上傳遞callback=?參數,實現跨域
- pajax入門
- jquery的extend插件制作
- jquery的兼容
- jquery的連續調用:
- $ 和 jQuery 及 $() 的區別
- 頁面響應順序及$(function(){})等使用
- 匿名函數:
- ajax
- 獲取js對象所有方法
- dom加載
- ES6函數寫法
- ES6中如何導入和導出模塊
- 數組的 交集 差集 補集 并集
- phantomjs
- js數組的map()方法操作json數組
- 實用函數
- js精確計算CalcEval 【價格計算】 浮點計算
- js精確計算2
- js數組與對象的遍歷
- bootstrap
- class速查
- 常見data屬性
- data-toggle與data-target的作用
- 組件
- bootstrapTable
- 表選項
- 表選項2
- 示例
- 數據格式(json)
- 用法(row:行,column:列)
- Bootstrap-table使用footerFormatter做統計列功能
- 示例2
- JQuery-Jquery的TreeGrid插件
- 服務器端分頁
- 合并單元格1
- 合并單元格2
- 合并單元格3
- 合并單元格4
- 合并單元格5(插件)
- 列求和
- 添加行,修改行、擴展行數據
- 擴展
- 開源項目
- PhpSpreadsheet
- 實例
- 會員 數據庫表設計
- 程序執行
- 開發總結
- API接口
- API接口設計
- json轉化
- app接口
- 雜項
- 三方插件庫
- 檢測移動設備(包括平板電腦)
- curl封裝
- Websocket
- 與谷歌瀏覽器交互
- Crontab管理器
- 實用小函數
- PHP操作Excel
- SSL證書
- sublime Emmet的快捷語法
- 免費翻譯接口
- 接口封裝
- 免費空間
- 架構師必須知道的26項PHP安全實踐
- 大佬博客
- 個人支付平臺
- RPC(遠程調用)及框架