PHP array vs [ ] in method and variable declaration

后端 未结 4 746
面向向阳花
面向向阳花 2020-12-14 14:39

I have a question about PHP syntax.

When defining functions and variables, which convention should I use?

I know they do the same thing in practice but I wou

4条回答
  •  执笔经年
    2020-12-14 14:56

    just made a test to see how [] performs vs array() here is what I got

    testing 1 million []s ( with $arr[] = [] )
    started at : 1561298821.8754
    ended at: 1561298822.6881
    difference: 0.81266021728516 seconds 
    
    testing 1 million array()s ( with array_push( $arr, array()) )
    started at : 1561298822.6881
    ended at: 1561298823.843
    difference: 1.1549289226532 seconds 
    
    testing 1 million []s ( again while the processor is hotter)
    started at : 1561298823.8431
    ended at: 1561298824.7448
    difference: 0.9017219543457 seconds 
    

    so [] performed about 20% faster

提交回复
热议问题