Basically what I meant is that instead of array_keys($_GET)[0] === 'favorites' You can do isset($_GET['favourites']) which should be faster in most cases. But an easier solution is like he said, storing array_keys($_GET)[0] in a variable and using that.
So you can put $firstget = array_keys($_GET)[0] at the top, and then replace every array_keys($_GET)[0] with $firstget.
Your current changes will break your site, so don't actually use it.