I have a page with many fields a user can fill out. The fields are not mandatory but I do not want to sent a empty value to mysql as that will create problems later on. I'm trying to create a loop that checks if a variable is empty, and if empty assign some static value. Because I got rather a lot of field vars I want to do this without having to specify each field var.
<?php
$arr = get_defined_vars();
foreach ($arr as $key => $value) {
if (empty($value))
echo "$key empty <br/>";
else
echo "$key not empty <br/>";
}
print_r($arr);
?>
Shows all fieldname:empty or fieldname:not empty.
I tried adding various things such as $arr[$key] = "TEST";
or $key = "TEST";
below if (empty($value))
but I cannot get the empty fields to update in the printed array.