PHP Array Efficiency and Memory Clarification
Posted
by CogitoErgoSum
on Stack Overflow
See other posts from Stack Overflow
or by CogitoErgoSum
Published on 2010-06-14T14:25:37Z
Indexed on
2010/06/14
14:32 UTC
Read the original article
Hit count: 235
When declaring an Array in PHP, the index's may be created out of order...I.e
Array[1] = 1 Array[19] = 2 Array[4] = 3
My question. In creating an array like this, is the length 19 with nulls in between? If I attempted to get Array[3] would it come as undefined or throw an error? Also, how does this affect memory. Would the memory of 3 index's be taken up or 19?
Also currently a developer wrote a script with 3 arrays FailedUpdates[] FailedDeletes[] FailedInserts[]
Is it more efficient to do it this way, or do it in the case of an associative array controlling several sub arrays
"Failures" array(){
["Updates"] => array(){
[0] => 12
[1] => 41
}
["Deletes"] => array(){
[0] => 122
[1] => 414
[1] => 43
}
["Inserts"] => array(){
[0] => 12
}
}
© Stack Overflow or respective owner