10 ms·
Shouldn't your third line print zero instead of negative one? Maybe negative one is a special result of an uninitialized array in perl? Hm. Anyway, the actua
by randallsquared 16y ago
Shouldn't your third line print zero instead of negative one? Maybe negative one is a special result of an uninitialized array in perl? Hm.
Anyway, the actual use case of populating an array and then deleting some elements works fine in PHP; I don't think there's any difficulty with expressing what you want -- it's just going to be somewhat less efficient than it could be. In your example, it's not clear to me what indexes zero through nine point to... null, maybe? In PHP, you'd have to be explicit about what values you wanted in zero through nine by using array_fill(), or live with:
for($i=0;$i<=10;$i++) {
if(!isset($array[$i])) continue;
// ...
}
If you use a for loop, you'd have to check each value to make sure it's defined like that. If you don't care about order in the loop, you could use foreach and avoid the check and a lot of extraneous looping.