$id = array_pop(explode("_", $key));
There's your problem ;)
explode will return an array.
Array_pop will take that array, and remove the last value from it.
But since you are not supplying Array_pop with an array (but rather a function that returns an array) it cannot modify the array for you.