Is there any way to access POST data by index, rather than accessing it through keys? I’d like the following code to work:
for($x = 0; $x < count($_POST); $x++)
echo $x . ": " . $_POST[$x];
(Yes, I know that count in the loop is bad, just using it for simplicity)
The problem is that apparently I can’t access the $_POST variable by index, it has to be accessed by key. The reason I can’t use keys is because I’m going to have variable form data, so there could be more or less in the POST, so I need to be able to loop through a variable number of keys, with variable names.
Any help is appreciated!
EDIT: To clarify, I was confused because I had previously assumed that PHP arrays behaved almost like C++ enumerations.
Use foreach() instead, it also works on numeric arrays.