I'm looking to create a variable with the name of a variable currently in use, with the word 'error' appended to the end.
Any ideas how i'd do this?
What i've tried so far
Code: Select all
$username = 1;
$mandatory_fields = array($username,$password);
for ($i=0; $i<=2; $i++) {
if (!(isset($mandatory_fields[$i]))) {
$mandatory_fields[$i].'error' = TRUE;
}
}
Looking at the for loop:
First loop: Nothing will happen because it doesn't meet the necessary if statement clause. I.E. the first element in the array exists, because its $username.
Second loop: create a variable by concatenating the variable name, which is $password, with the string "error", and then set the variable to boolean TRUE. So the loop generates $usernameerror=TRUE because $password hasn't been set.
Hope that makes sense.
If anyone can think of a better way of doing it, i'd be greatful for any tips.
Thanks for any help in advance,
Matthew Millar