PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Why do you concatenate the strings after the foreach loops instead of during? And whats with the "${$k} = $v?" Is that a pseudo register_globals kind of thing going on?
I appreciate where you are coming from Defkon1 and thanks for the contribution. These variables do often need to be output when debugging, especially if you are unfamiliar with the code. However for most occasions a simple var_dump/print_r will suffice and you get used to reading it very quickly. I generally only place them in code when I get a problem/bug occuring, removing them immediately afterwards. Things like $_POST,$_GET and even $_COOKIE are normally a single level array and quite small. On the very rare instance where I would like a more "user friendly" view (multiple nested session variables is an example that springs to mind) I tend to use a collapsing tree display which I simply plug in (example). I feel this is justified (stress only rarely) as it adds additional functionailty compared with var_dump/print_r.
Defkon1 wrote:why do you think it's terrible? (i'd like to improve my knowledge...)
Imagine you have a value in your $_SESSION array called 'id' and you convert it into $id to use it. If I go to page.php, but I added ?id=1 to the URL so I was viewing page.php?id=1, what happens? Your code has overwritten the $id value from $_SESSION with my value in $_GET. Fortunately in your script it'd only be visible in the scope of the function, but it's still a really bad idea. It's precisely why register_globals is switched off by default in php.ini these days.