Last active
August 29, 2015 14:02
-
-
Save chrisveness/bddda6b9b0759e0eb4db to your computer and use it in GitHub Desktop.
Clean up posted data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cleans up posted data - trims texts & converts empty fields to null. | |
* | |
* @param mixed[] $post POST data to be cleaned. | |
* @return mixed[] Cleaned-up POST data. | |
*/ | |
function clean($post) | |
{ | |
foreach ($post as $key=>$val) if (is_string($val)) $post[$key] = trim($val); | |
foreach ($post as $key=>$val) if ($val === '') $post[$key] = null; | |
return $post; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment