PHP的array_diff()函數(shù)在處理大數(shù)組時的效率問題
Jun 13, 2016 pm 12:03 PM
cisa 提交到 PHP 官方 BUG 頁面上的方法
復制代碼 代碼如下:
/**
* 解決 php 5.2.6 以上版本 array_diff() 函數(shù)在處理
* 大數(shù)組時的需要花費超長時間的問題
*
* 整理:http://www.CodeBit.cn
* 來源:http://bugs.php.net/47643
*/
function array_diff_fast($data1, $data2) {
$data1 = array_flip($data1);
$data2 = array_flip($data2);
foreach($data2 as $hash => $key) {
if (isset($data1[$hash])) unset($data1[$hash]);
}
return array_flip($data1);
}
?>
根據 ChinaUnix 論壇版主 hightman 思路重寫的方法
復制代碼 代碼如下:
/**
* 解決 php 5.2.6 以上版本 array_diff() 函數(shù)在處理大數(shù)組時的效率問題
* 根據 ChinaUnix 論壇版主 hightman 思路寫的方法
*
* 整理:http://www.CodeBit.cn
* 參考:http://bbs.chinaunix.net/viewthread.php?tid=938096&rpid=6817036&ordertype=0&page=1#pid6817036
*/
function array_diff_fast($firstArray, $secondArray) {
// 轉換第二個數(shù)組的鍵值關系
$secondArray = array_flip($secondArray);
// 循環(huán)第一個數(shù)組
foreach($firstArray as $key => $value) {
// 如果第二個數(shù)組中存在第一個數(shù)組的值
if (isset($secondArray[$value])) {
// 移除第一個數(shù)組中對應的元素
unset($firstArray[$key]);
}
}
return $firstArray;
}
?>
此方法只交換了第二個數(shù)組的 key 和 value,所以效率更高。
注意:PHP 內置的 array_diff() 函數(shù)可以處理多個數(shù)組,而本文提供的方法只處理了兩個數(shù)組的比較。

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

??? ??











PHP?? ?? ?? ID? ?? ??? Session_id () ??? ???? ???? Session_Start ()? ???? ????? ??????. 1. ??? ????? ?? _start ()? ?????. 2. Session_id ()? ???? ?? ID? ?? ABC123DEF456GHI789? ??? ???? ?????. 3. ??? ?? ??? Session_Start ()? ??????, ???? ???? ?????? ?? ??? ?????? ??? ??????. 4. ?? ID? ??, ?? ?? ? ?? ?? ??? ??? ? ??? ?????? ???????. ??? ???? ????? ID? ????? ?? ? ??? ??????.

PHP ????? ?? ???? ????? Syntax substr (String $ String, int $ start,? int $ length = null) ? substr () ??? ??? ? ??? ??? ???? ??? ??? ?????. ???? ?? ?? ??? ??? ?? ? ?? MB_SUBSTR () ??? ???? ?? ??? ??????. ?? ???? ?? ???? ?? ????? ?? exploit () ?? strtr ()? ???? ?? ?? ??? ?? ??? ?? ??? ?? ??? ? ????.

UnitTestingInphPinvolvesVeverifying individualCodeUnitsInitsIntsormeStodStocatchBugSearlyLylyLearLiAberFactoring.1) setupphPunitviacomposer, createEatestDirectory, and ConfigeAuteAutoloadandPhpunit.xml.2) writeTestCases-oct-oct-asserterfat

PHP?? ?? ???? ??? exploit () ??? ???? ???? ??? ???? ????. ? ??? ??? ?? ??? ?? ???? ?? ???? ??? ??? ?????. ??? Exploit (???, ???, ??)??, ??? ???? ????? ???? ?? ?????, ??? ????? ?? ?? ?????? ??? ?? ?????. ?? ?? $ str = "Apple, Banana, Orange"; $ arr = Explode ( ",", $ str); ??? [ "Apple", "Bana???

JavaScript ??? ??? ?? ?? ? ?? ???? ????. ?? ???? ???, ??, ??, ?, ???? ?? ? ??? ?????. ?? ????? ?? ?? ? ? ??? ????? ?? ??? ??? ????. ??, ?? ? ??? ?? ?? ??? ??? ??? ???? ??? ??? ???? ??? ?? ??? ????. ?? ? ????? ??? ???? ? ??? ? ??? TypeofNull? ??? ?????? ??? ? ????. ? ? ?? ??? ???? ?????? ????? ???? ??? ???? ? ??? ? ? ????.

JavaScript?? ??? ?? ?? ???? ??? ??????. ?? ???? ??? ?? ?? ???? ()? ??? array.includes (valuetofind)???. ?? ??? ?? ???? ?? ??. indexof (20)! == -1? ?? indexof ()? ??????. ?? ?? ??? ???? ?? user.some (user => user.id === 1)? ?? ?? ??? ?? () ???? ???????.

STD :: Chrono? ?? ?? ??, ?? ?? ??, ?? ?? ? ?? ?? ? ?? ?? ??? ???? C?? ???? ??? ?????. 1. std :: chrono :: system_clock :: now ()? ???? ?? ??? ?? ? ??? ?? ??? ???? ?? ? ? ??? ??? ??? ???? ?? ?? ? ????. 2. std :: Chrono :: steady_clock? ???? ?? ??? ???? ?? ??? ???? duration_cast? ?? ?? ?, ? ? ?? ??? ??????. 3. ?? (time_point) ? ?? (??)? ?? ??? ? ? ??? ?? ??? ? ?? epoch (epoch)???? ???????.

PHP?? ?? ??? ?? ???? ????? ?? ??? ???? ???? ??? $ _session ? ??? ???? ????. 1. ? ???? ?? ??? ???? ?? Session_Start ()? ???? ???? ??? ???????. 2. $ _session [ 'username'] = 'johndoe'? ?? ?? ??? ?????. 3. ?? ????? session_start ()? ?? ? ? ??? ? ??? ?? ??? ???????. 4. Session_Start ()? ? ????? ???? ??? ????, ???? ?? ???? ??, ??? ?? ???? ??? ?? ? ? ??? ??????. 5. SES? ??????
