Apparently there is some confusion as to what I am talking about.
It has to do with this:
foreach($array as $key => $value)
{
do_something_with($key);
}
Versus this:
foreach($array as $key => $key)
{
do_something_with($key);
}
My post has ABSOLUTELY NOTHING to do with the function array_key.
I am wondering if the code below is valid php code.
foreach($array as $key => $key)
{
do_something_with($key);
}
The reason I don't want to use array_key is because it is:
1) slower (I checked)
2) less memory efficient (I checked)
3) More code
Again I will state my questions with regards to the following code:
foreach($array as $key => $key)
{
do_something_with($key);
}
1) Is this valid PHP code?
2) Is the behavior going to change in newer or older versions of PHP? (Basically is it going to start populating $key with "value information"?)
3) Is what I am doing reliable?
4) Did the php people design it that way? Or am I just exploiting some sort of glitch which might change with time?