I have an array that received about 12 potential key / value pairs. It is based on _POST / _GET
The keys are not numeric, as in 0-n, and I need to store the keys where applicable. My problem is that I know that sometimes a key will be passed where the value is null, empty or equal to "". In case I want to trim these keys before processing the array. As it runs down the line, there is not something that will break my script.
Now, some time ago, I either did or found this function (I don’t remember what it was in my arsenal for a while, at least).
function remove_array_empty_values($array, $remove_null_number = true) { $new_array = array(); $null_exceptions = array(); foreach($array as $key => $value) { $value = trim($value); if($remove_null_number) { $null_exceptions[] = '0'; } if(!in_array($value, $null_exceptions) && $value != "") { $new_array[] = $value; } } return $new_array; }
What I would like to do is very similar to this, however it works well with arrays that can have nn key values, and I am not dependent on the key, as well as on the value, to determine what is where, when. As stated above, you just delete everything and then just restore the array. Where I am stuck, trying to figure out how to simulate the above function, but where I save the keys I need.
chris source share