This is a style question, I suppose. Why do people go through the trouble of assigning a variable with $_GET and $_POST data in PHP? For example, why do this:
<?php
$name = $_GET['name'];
echo $name;
?>
when you can just do this instead?
<?php
echo $_GET['name'];
?>
There are several reasons:
It’s easier to write, especially when including inside a string.
You only have to sanitize it once and know that whenever you’re calling the interim variable it is the sanitized version.
(this is a big one) $_GET and $_POST variables are available globally, which means that multiple functions or statements may depend on its value. If you ever need to modify a variable ($_GET[‘var’]++, for instance) it may be important that you are not affecting other functions. Thus it’s safer to store the value in a working variable in case the $_GET or $_POST variable ever gets used in another place.
If you have to access the variable multiple times, reading it out of the array each time will be slower… I’m tempted to leave this out of the list altogether, as the difference is so vanishingly small, but when some people optimize large loops they will store the variable outside the array. However, even after hundreds of thousands of reads the speed difference may not be noticeable, so it’s not a particularly compelling addition to the list.