DIGIT-ARC read-only archive · snapshot: July 23, 2026

php array adding to empty array

3 posts · originally from https://geek.digit.in/community/threads/php-array-adding-to-empty-array.141330/

B
bagsfr Original post #1
May 26, 2011 at 3:09 PM
I am using array to add up numbers from database and wonder if this would be valid:

$array[10] = $array[10] + 1

However the initial array has not been set and is without value. Would it assume that it is equal to 0 and after the above line become 1?

I hope I am explaining this right

Thanks
krishnandu.sarkar
May 26, 2011 at 3:28 PM
Ya, it'll work, but not sure about the initialization thing. It's recommended to initialize them to 0.
furious_gamer
May 26, 2011 at 6:31 PM
it will work, if $array[10] already have values.