發表文章

目前顯示的是 十二月, 2014的文章

[PHP] 將陣列中重複的值刪除最好方法 array_flip (移除陣列中重複的值)

使用array_fliparray_unique來的快速
參考連結:http://stackoverflow.com/questions/8321620/array-unique-vs-array-flip
上述網址提供的範例: http://codepad.org/AnpS69yw

用途: // 使用前的陣列 Array ( [0] => 8 [1] => 9 [2] => 10 [3] => 11 [4] => 10 [5] => 11 [6] => 8 [7] => 9 ) // 使用後的陣列 Array ( [6] => 8 [7] => 9 [4] => 10 [5] => 11 )
$test=array(); for($run=0; $run<1000; $run++) $test[]=rand(0,100); $time=microtime(true); for($run=0; $run<100; $run++) $out=array_unique($test); $time=microtime(true)-$time; echo 'Array Unique: '.$time."\n"; $time=microtime(true); for($run=0; $run<100; $run++) $out=array_keys(array_flip($test)); $time=microtime(true)-$time; echo 'Keys Flip: '.$time."\n"; $time=microtime(true); for($run=0; $run<100; $run++) $out=array_flip(array_flip($test)); $time=microtime(true)-$time; echo 'Flip Flip: '.$time."\n"; 結論: array_unique($test); …

[PHP] 暫存檔 JSON, serialize or var_export?

文章 Cache a large array: JSON, serialize or var_export?

904 B arrayJSONSerializationvar_export / includeLength105150151Encoding0.00006604194641110.000046968460083010.00014996528625488Decoding0.00111603736877440.000926971435546880.0010221004486084
18.07 kB arrayJSONSerializationvar_export / includeLength196527903103Encoding0.00050401687622070.000359058380126950.001352071762085Decoding0.00172901153564450.00112986564636230.0056741237640381
290.59 kB arrayJSONSerializationvar_export / includeLength317254503058015Encoding0.00768494606018070.00574803352355960.02099609375Decoding0.0149559974670410.0101778507232670.030472993850708
4.54 MB arrayJSONSerializationvar_export / includeLength5078857208701059487Encoding0.138731956481930.118417024612430.38376498222351Decoding0.298709869384770.215907812118530.53850317001343
72.67 MB arrayJSONSerializationvar_export / includeLength81264451153431019049119Encoding2.30550408363342.76090407371526.2211949825287Decoding4.51910996437078.3514900207528.7873070240021