I would like to simplify this PHP process that checks if a value is blank.
If the value is blank, the variable gets set to null. If not, the variable is set to the value.
In this case, I have successfully posted a jquery object (called criteria) to PHP for processing. I then set the variables to the values in the object. I use IF/ELSE statements to check if the object value is blank.
<?php
if(isset($_POST['criteria']))
{
$value = $_POST['criteria'];
if($value['recentsq'] == ""){$recentsq = null;}else{$recentsq = $value['recentsq'];}
if($value['custname'] == ""){$custname = null;}else{$custname = $value['custname'];}
if($value['address'] == ""){$address = null;}else{$address = $value['address'];}
}
?>
I have quite a few of these values I need to check and set.
My question is how can I simplify this process by using a custom function?