&$value) { if (is_array($value) /* Recursive function call here. */) $value = c_ws_plugin__s2member_utils_arrays::remove_nulls ($value); else if (is_null /* Is it null? */ ($value)) unset($array[$key]); } return $array; } /** * Removes all 0-byte strings from an array *(or even a multi-dimensional array)*. * * @package s2Member\Utilities * @since 111216 * * @param array $array An input array. * @return array Returns the ``$array`` after having reduced its set of values. */ public static function remove_0b_strings ($array = FALSE) { $array = (array)$array; foreach ($array as $key => &$value) { if (is_array($value) /* Recursive function call here. */) $value = c_ws_plugin__s2member_utils_arrays::remove_0b_strings ($value); else if (is_string ($value) && !strlen ($value)) unset($array[$key]); } return $array; } /** * Forces string values on each array value *(also supports multi-dimensional arrays)*. * * @package s2Member\Utilities * @since 111101 * * @param array $array An input array. * @return array Returns the ``$array`` after having forced it to set of string values. */ public static function force_strings ($array = FALSE) { $array = (array)$array; foreach ($array as &$value) { if (is_array($value) /* Recursive function call here. */) $value = c_ws_plugin__s2member_utils_arrays::force_strings ($value); else if (!is_string ($value) /* String? */) $value = (string)$value; } return $array; } /** * Forces integer values on each array value *(also supports multi-dimensional arrays)*. * * @package s2Member\Utilities * @since 111101 * * @param array $array An input array. * @return array Returns the ``$array`` after having forced it to set of integer values. */ public static function force_integers ($array = array()) { $array = (array)$array; foreach ($array as &$value) { if (is_array($value) /* Recursive function call here. */) $value = c_ws_plugin__s2member_utils_arrays::force_integers ($value); else if (!is_integer ($value) /* Integer? */) $value = (int)$value; } return $array; } /** * Sorts arrays *(also supports multi-dimensional arrays)* by key, low to high. * * @package s2Member\Utilities * @since 111205 * * @param array $array An input array. * @param int $flags Optional. Can be used to modify the sorting behavior. * See: {@link http://www.php.net/manual/en/function.ksort.php} * @return Unlike PHP's ``ksort()``, this function returns the array, and does NOT work on a reference. */ public static function ksort_deep ($array = FALSE, $flags = SORT_REGULAR) { $array = (array)$array; ksort /* Sort by key. */ ($array, $flags); foreach ($array as &$value) if (is_array($value) /* Recursive function call here. */) $value = c_ws_plugin__s2member_utils_arrays::ksort_deep ($value, $flags); return /* Now return the array. */ $array; } /** * Like maybe_unserialize(), but skips objects. * * @package s2Member\Utilities * @since 250801 * * @param mixed $value The value to be unserialized. * @return mixed The unserialized value, or original if not serialized or blocked. */ public static function maybe_unserialize($value) { if (!is_string($value) || !is_serialized($value)) { return $value; } $value = trim($value); if (version_compare(PHP_VERSION, '7.0.0', '>=')) { return @unserialize($value, ['allowed_classes' => false]); } if (strpos($value, 'O:') !== false) { do_action('ws_plugin__s2member_security_object_detected', $value); return null; } return @unserialize($value); } } }