Today, I saw a colleague writing PHP program suddenly want to test the two types of PHP array definition of performance differences
The simple test code is as follows:
1. Use the array keyword
0, ' b ' and ' = 1, ' c ' = 2, ' d ' + 3, ' E ' + 4, ' F ' + 5, ' g ' = 6, ' h ' = 7, ' i ' = 8, ' j ' and 9, ' K ' and 10 , ' l ' +-one, ' m ' = +, ' n ' = +, ' o ' = +, ' p ' = +, ' q ' = +, ' r ' = +, ' s ' = ', ' t ' = ' u ' = +, ' V ' = +, ' w ' = +, ' x ' = +, ' y ', ' + ', ' z ', ' + ', ' A1 ' + 0, ' B1 ' + 1, ' C1 ' + 2, ' D1 ' => ; 3, ' E1 ' and 4, ' F1 ' and 5, ' G1 ' and 6, ' H1 ' + 7, ' i1 ' + 8, ' j1 ' = 9, ' k1 ' and ' = ', ' l1 ' and ' = ', ' M1 ' and 12, ' N1 ' +, ' o1 ' = +, ' p1 ', ' Q1 ', ' + ', ' R1 ' + +, ' s1 ' + +, ' T1 ' +, ' U1 ', ' v1 ' = ' W1 ' and ' x1 ', ' y1 ', ' Z1 ' and ' 25 ';} Echo '
'; echo time (); exit ();
Execution time: 1398407484-1398407432 = 52s
2. Do not use the array keyword
'; echo time (); exit ();
Execution Time 1398407870-1398407832 = 38s
They have a huge performance correlation.
So it's best to use a single-row definition when defining an array although this can be a good way to write more code, but some of the higher performance is nice, especially on the most visited sites, especially if you're a C-born programmer.