You really need to learn how to debug your code. If you don't have an IDE with a symbolic debugger then you should put some echo statements into you code to display what values are appearing in your variables.
I spotted one mistake straight away - after you unpack the string into an array with $gr_key_array = explode('&', $str_gr_art);
you reference the three parts with indexes [1], [2] and [3]. This is wrong as the array starts with index [0].