Jump to content

PHP Search Form - Help


Recommended Posts

is this enough? :

function custOut($val){ //declare function to check values, take in any variable passed to it and assign it to $val while it's inside the function
  if (is_array($val)){ // check if the variable that was passed in is an array, if it is
    foreach($val as $k=> $v){ //run through the array, assigning the keys as $k and the vaules as $v
      if(trim($v) == '' || empty($v) || !isset($v)){ //if the value (once all empty space has been removed) is an empty string, or if the value is false, or if the value is not set
        $v = 'N/A'; //make the value = to the string 'N/A'
      }//close if value check
    }//close for each
  } //cloase if array
  else{ // if the value passed in is not an array
    if(trim($val) == '' || empty($val) || !isset($val)){ //perform the same check directly to the value that was passed into the function
      $val = 'N/A'; // and applt the string value of 'N/A' if it matches the check
    }//close if check
  }//close else
return $val; //now that we are done we can return the value of $val back to the main code, only changed if it met with the checks and exactly as it was if it didn't
} // end of function. nb. If we didn't return anything the rest of the code would have no access any changes made in the function

Link to comment
Share on other sites

  • Replies 52
  • Created
  • Last Reply


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.