use php array element as variable name
Posted: Wed Oct 07, 2009 1:07 pm
Hi,
I've manually written out an array, and was hoping to create individual variables for each of the array elements.
Is this possible?
Basically, i'm looking for a way of echoing potential errors.
The purpose of the mandatory field element varaible, is i'd echo that variable next to the mandatory html field, if theres no problem, it'll be blank, if there is, the user will see the error.
Does anyone know of a better way of doing this, if its not possible to do what i had hoped?
Thanks,
Matthew Millar
I've manually written out an array, and was hoping to create individual variables for each of the array elements.
Code: Select all
$mandatory_fields = array('company_postcode','company_country','company_telephone','account_email','account_forename','account_surname');
for ($i=0; $i = count($mandatory_fields) -1; $i++) {
if ($_POST[$mandatory_fields[$i]] = "") {
$ //i want this variable, if $i were 0, to be $company_postcode
}
}
Basically, i'm looking for a way of echoing potential errors.
The purpose of the mandatory field element varaible, is i'd echo that variable next to the mandatory html field, if theres no problem, it'll be blank, if there is, the user will see the error.
Does anyone know of a better way of doing this, if its not possible to do what i had hoped?
Thanks,
Matthew Millar