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!
This is because you are reading the key of the Array as a variable. You are not resetting anything. Even though you are telling the script that as you walk the array, if it finds this particular key, change the variable known as key to this particular value, it doesn't change the key value of the array, just the key value in the foreach array loop.
I am looking for a way to do what you want. When I find I will post it.
Jcart wrote:Why don't you try running your code? From what I can see it should work you expect.
The variable $key is only available within the scope of the foreach loop. It is not changing the key but rather echoing the changed value of the key within the foreach loop. The key will still be the same after the foreach loop ends.
Everah wrote:I agree with Feyd. There is no way to destroy or change the value of key (without rewriting the array from top to bottom).
Yeah, that's what I did.
When posting the topic, I thought there might be some little trick I didn't know to change key value without declaring a new array which I see doesn't exist. Not a problem though .