我有閱讀整個文件中的數組(十六進制)後存儲在內存中一個非常大的陣列是這樣的:PHP大數組操作
$bin_content = fread(fopen($filename,"r"),filesize($filename));
$hex_decode = explode(" ",chunk_split(bin2hex($bin_content),2," "));
unset($bin_content);
function myfunction($i) {
global $hex_decode;
// stuff here
}
當我創建一個使用此$hex_decode
數組作爲全球功能...腳本像永遠一樣運行(非常慢),但是如果我將該函數作爲參數傳遞給$hex_decode
(myfunction($i,$hex_decode) instead of myfunction($i) in which $i is a pointer
),則事情會更快。
任何人都可以解釋爲什麼嗎?有沒有什麼方法通過用不同的方法讀取文件來加速腳本。
我需要將數組中的整個文件逐行排列,因爲我構建了一個自定義的ASN.1解碼器,並且我需要全部使用它。
避免全局性的另一個原因。 – Zenexer 2012-02-08 08:16:40
如果您要一次讀取所有文件,請使用爲其創建的函數:'file_get_contents'。 – deceze 2012-02-08 08:22:43
所以在PHP中的全局有問題?謝謝你的答案 – pufos 2012-02-08 08:27:23