I found some old code that i created a while back when I first started programming, I was pushing 50+ elements into an array rather then creating them inside the array at the start.
Am i effecting performance when I push multiple elements into my array rather then just create the array containing the elements at the start.
答案 0 :(得分:0)
plz check link
答案 1 :(得分:0)
array_push()
比$array[]
慢。在PHP docs,有人做了一个很好的性能测试。
我猜是因为内部实现。可能每次都会创建一个新数组和/或分配新内存,这会使它更慢。但我们谈论的是数百或数千条记录。任何不足都不会对绩效产生明显影响。