Skip to content
Advertisement

PHP behaving strange in for loop with associative array

the attached image is self-explanatory. I think its not new, but i’d like to understand the details behind it. So to summarize my problem, when an associative array, that has only string keys, is passed to a basic for loop, it overflows, when i assign a value to one of its – previously non existant – indexed keys. Why is that? (The image if from tehplayground php sandbox, but does the same on local machine @ PHP 7.3.2 PHP sandbox run img

JavaScript

Advertisement

Answer

do like this if you want to run loop based on before everything count:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement