PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
$count=count($blabla);
for ($i=0;$i<10;$i++)
{
$blabla[$count++]="hullahoop";
echo "<br>key:".($count-1);
}
With regards to key and current, they are only defined when you're using each() and its ilk.
Just using $i wouldn't work, if there were already entries in the array. Using a post-incrementing count ensures that no cell is over-written as long as you always auto-assign or use post-incrementing count. If you start assigning a sparse array you will have trouble.
Fair 'nuff. I don't like mixing sparse arrays with auto-assignment.
Be aware that if you nest the array_pop(array_keys()) method inside a loop, you're going to be looking at a O(n^2) algorithm.
If you're positive that the last inserted element is the largest and you want to start inserting above it, then combine the two approaches. Replace $count with $max, and initialize it to the last key. Change post-incremenet to pre-increment and you should be all set with an O(n) method.
True, nielsene. I am using this to move array-elements up and down an array and need the absolute array-position of an element in a auto-incremented array.