When I print_r it returns an array of data.
print_r($_POST);
My input fields are standard address information and a patient id:
Array ( [patient_id] => this [Last] => that [First] => Ted [ADDRESS1] => dey
[DOB] => [email] => [insurance_id] => [Phone] => [State] => CA [Zip] => 91236
[Status] => 3 [select_top] => 17 )
For status it's usually going to be entered as a 1, 2, or 3.
How can I change the POST value so when a 3 is entered it's returned as Inactive or 2 returned as Active?
Is it possible to do a foreach loop and just change the value to an alias or something?
foreach($_POST as $key => $val){
if($key == '3') $val = Inactive;
}
Any help would be greatly appreciated.
You can use a switch statement. There's no need to use a foreach loop:
switch($_POST['status']) {
case 1: $_POST['status'] = 'Lead'; break;
case 2: $_POST['status'] = 'Active'; break;
case 3: $_POST['status'] = 'Inactive'; break;
default: $_POST['status'] = 'Huh?';
}
Rather than manipulate the $_POST super global, I'd rather look up the value from a known set of valid entries. For example
$statusValues = array(
1 => 'Lead',
2 => 'Active',
3 => 'Inactive'
);
if (!array_key_exists($_POST['status'], $statusValues)) {
throw new UnexpectedValueException($_POST['status']);
}
$status = $statusValues[$_POST['status']];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With