来自$ _GET的foreach循环正在添加奇怪的值

I have the following piece of code that is supposed to create a coma separated string from a URL returned when somebody installs a Facebook Tab:

$tabs_added = $_GET['tabs_added'];
$tabs_added_array = array();
foreach($tabs_added as $key => $value){
    $tabs_added_array[] = $key;
}
$the_tabs = implode(',', $tabs_added_array);

The page is called and returned by Facebook like this:

tabs.php?tabs_added[1202358366491085]=1&tabs_added[144695175064017]=1
&tabs_added[676066073448810]=1#_=_

For some strange reason, the string it generates however is:

1202358366491085,144695175064017,676066073448810,0,1,2

As you can see, the beginning is correct, but then it adds 0,1,2 for no reason. Why is that and how can I avoid this?

Your array looks like this:

[0]=>[1202358366491085]
[1]=>[144695175064017]
[2]=>[676066073448810]

Try it out with: var_dump($tabs_added_array); after the foreach.

And the string gets both. The code you show is not producing the indexes of the array though.

I've tested this myself and this is the URL I have:

test.php?
tabs_added[1202358366491085]=1&tabs_added[144695175064017]=1
&tabs_added[676066073448810]=1#_=_

And my code:

$tabs_added = $_GET['tabs_added'];
$tabs_added_array = array();
foreach($tabs_added as $key => $value){
    $tabs_added_array[] = $key;
}
$the_tabs = implode(',', $tabs_added_array);
var_dump($tabs_added_array);

There must be something else in the code you're not showing us whether you know it or not.

I ended up doing this to fix my problem:

foreach($tabs_added_array as $key => $val) {
    if(strlen($val) <= 3)
        unset($tabs_added_array[$key]);
}

Yes, it's a dirty fix. But I didn't know how else to do it. It didn't fix the problem, but it's a solution.