foreach ($array as $key => $value)
にして、$keyにアクセスしてる?