| @@ -160,8 +160,30 @@ | ||
| 160 | 160 | } |
| 161 | 161 | return $array; |
| 162 | 162 | } |
| 163 | 163 | /** |
| 164 | + * Sets specified array elements to an empty string when they are not set according to ``isset()`` (missing or NULL). | |
| 165 | + * | |
| 166 | + * @package s2Member\Utilities | |
| 167 | + * @since 260814 | |
| 168 | + * | |
| 169 | + * @param array $array An input array. | |
| 170 | + * @param array $keys Array keys whose unset elements should be set. | |
| 171 | + * @return array Returns the ``$array`` after setting unset elements to empty strings. | |
| 172 | + */ | |
| 173 | + public static function set_unset_elements ($array = FALSE, $keys = FALSE) | |
| 174 | + { | |
| 175 | + $array = (array)$array; | |
| 176 | + $keys = (array)$keys; | |
| 177 | + | |
| 178 | + //260814 isset() treats both missing keys and null values as unset; initialize either case to an empty string. | |
| 179 | + foreach ($keys as $key) | |
| 180 | + if (!isset($array[$key])) | |
| 181 | + $array[$key] = ''; | |
| 182 | + | |
| 183 | + return $array; | |
| 184 | + } | |
| 185 | + /** | |
| 164 | 186 | * Forces string values on each array value *(also supports multi-dimensional arrays)*. |
| 165 | 187 | * |
| 166 | 188 | * @package s2Member\Utilities |
| 167 | 189 | * @since 111101 |