I have a variable set coming in from a form, and due to poor design by the original developer, the form will submit empty form element values as '' (empty single quotes), this wreaks havoc with some of the queries I am having to write because the functions read those as being values. I wrote a function to set any instances of '' to false, mainly because just capturing for if the value is false wasn't working. I re-wrote the function to be recursive in order to drill down into nested arrays.
function validateVars($vars){
foreach($vars as $k => $v){
is_array($k) ? validateVars($k) : $vars[$k] = ($v == '' ? FALSE : $v);
}
return $vars;
}
problem is, it sets all of the indexes with '' as the value to false as it should, but it isn't actually going into the arrays to set their values. Here's a sample dump:
array(14) {
["title"]=> string(3) "JLR"
["issue"]=> array(3) {
["jobs"]=> string(11) "66055,66056"
["Ids"]=> string(0) ""
["DateRange"]=> string(0) "" }
["article"]=> array(2) {
["Jobs"]=> string(0) ""
["Ids"]=> string(0) "" }
["issueDateFields"]=> string(11) "DateCreated"
["articleDateRange"]=> bool(false)
["articleDateFields"]=> string(11) "DateCreated"
["AdsJobs"]=> bool(false)
["FMBMJobs"]=> bool(false)
["AdsIds"]=> bool(false)
["FMBMIds"]=> bool(false)
["adsDateRange"]=> bool(false)
["adsDateFields"]=> string(11) "DateCreated"
["fmbmDateRange"]=> bool(false)
["fmbmssueDateFields"]=> string(11) "DateCreated"
}