is there a way to dynamically access $_GET
and $_POST
in one go? IE, something like:
$do = array('GET', 'POST');
foreach($do AS $type) {
foreach (${'_'.type} AS $var=>$val) {
... # logic
}
}
I understand that there is $_REQUEST
, but that doesn't tell me source (get or post) and that there are deprecated HTTP_GET_VARS
and HTTP_POST_VARS
, but those are deprecated.
Clearly, I can just loop individually. The reason why I'm trying to avoid this is that the logic is a little lengthy but also identical. It would be ideal to not have to have a copy of this logic and open myself up to mistakes.
Or am I completely thinking about this the wrong way and there is some other recommended approach?
Thanks!
Thank you
Thank you for the great feedback everyone. I think @deceze answers the question most objectively, but @charlee (and later deceze as well) alludes to a better solution.
In the end, I created a function with logic and then placed that in my foreach, as such:
foreach($_GET AS $var => $val) {
$_GET[$var] = func($val);
}
I do end up with two foreach()'s, but I appreciate the legibility and increased usability. Thank you again everyone!