Run array_filter recursively on an array
@link http://stackoverflow.com/a/6795671

@param  array $array
@return array
482350
protected function arrayFilterRecursive($array)
    {
        foreach ($array as &$value) {
            if (is_array($value)) {
                $value = $this->arrayFilterRecursive($value);
            }
        }

        return array_filter($array);
    }
1012481
static public function sortByKeyRecursive(array $array)
    {
        ksort($array);
        foreach ($array as $key => $value) {
            if (is_array($value) && !empty($value)) {
                $array[$key] = self::sortByKeyRecursive($value);
            }
        }

        return $array;
    }
1003556
public static function filterRecursive($array, $callback = null)
	{
		foreach ($array as &$value)
		{
			if (is_array($value))
			{
				$value = $callback === null ? static::filterRecursive($value) : static::filterRecursive(
																					  $value,
																						  $callback
				);
			}
		}

		return $callback === null ? array_filter($array) : array_filter($array, $callback);
	}
1179318
public function regex($array = [])
    {
        $filtered = [];
        foreach ($array as $key => $value) {
            if ($this->isRegex($key)) {
                $filtered[$key] = $value;
            }
        }

        return $filtered;
    }
239692
private function getArrayValue(array $array)
    {
        $value = [];
        foreach ($array as $item) {
            if ($item instanceof Keyword) {
                $item = $this->getKeyword($item);
            }
            $value[] = trim(str_replace(array("\n", "\r"), '', strip_tags('' . $item)));
        }

        array_walk($value, function(&$item) { return trim(str_replace(array("\n", "\r"), '', strip_tags('' . $item))); });

        return implode(',', array_filter($value));
    }
471507
private function rksort(array $array)
    {
        ksort($array);
        foreach ($array as $k => $v) {
            if (is_array($v)) {
                $array[$k] = $this->rksort($v);
            }
        }
        return $array;
    }
1078684
private function kSortRecursive(array &$array)
    {
        foreach ($array as &$current) {
            if (is_array($current) &&
                $this->kSortRecursive($current) === false
            ) {
                return false;
            }
        }
        return ksort($array);
    }
79110
public function arrayKeysSnakeRecursive($array)
    {
        $result = [];

        $array = arrayable($array) ? $array->toArray() : $array;

        array_walk($array, function ($value, $key) use (&$result) {
            $result[snake_case($key)] = arrayable($value) || is_array($value)
                ? $this->arrayKeysSnakeRecursive($value)
                : $value;
        });

        return coollect($result);
    }
269632
private function arrayFlatten(array $array)
    {
        $flat = array();
        foreach ($array as $arg) {
            switch (gettype($arg)) {
                case 'array':
                    $flat = array_merge($flat, $arg);
                    break;

                default:
                    $flat[] = $arg;
                    break;
            }
        }

        return $flat;
    }
1153113
protected function getOnlyStringKeys(array $array)
    {
        $allowed = array_filter(array_keys($array), function ($key)
        {
            return ! is_int($key);
        });

        return array_intersect_key($array, array_flip($allowed));
    }
1113208
public static function array_map_recursive($f, $array)
    {
        $applyOrRecurse = function ($v) use ($f) {
            return is_array($v) ? ArrayLib::array_map_recursive($f, $v) : call_user_func($f, $v);
        };

        return array_map($applyOrRecurse, $array);
    }
1281462
public static function ksortRecursive(&$array)
    {
        if (!is_array($array)) {
            return false;
        }

        ksort($array);
        foreach ($array as $key => $value) {
            static::ksortRecursive($array[$key]);
        }

        return true;
    }
157698
public static function filterKeys ($array, $keys)
		{
			if (is_array($array))
			{
				$return = [];
				if (!is_array($keys))
					$keys = [ $keys ];
				foreach ($keys as $key)
					if (isset($array[ $key ]))
						$return[ $key ] = $array[ $key ];

				return $return;
			}

			return null;
		}
701576
public static function filter(array $array, $method)
    {
        //if the method is valid
        if (gettype($method)==='object') {
            $out = [];
            foreach ($array as $key=>$value) {
                //true if key and value satisfy the method
                if (call_user_func_array($method, [$key,$value])) {
                    $out[$key] = $value;
                }
            }
            return $out;
        } else {
            //send error message if the given method is not valid
            system::add_error('ary::filter()', 'missing_function', 'second parameter must be a function object');
        }
    }
1293405
protected function array_filter_recursive(array $input)
    {
        foreach ($input as &$value) {
            if (is_array($value)) {
                $value = $this->array_filter_recursive($value);
            }
        }

        return array_filter($input);
    }
977839
protected function filter(array $array)
    {
        $config = collect(array_dot($array))->map(function ($value, $key) {
            if (str_contains($key, $this->hidden)) {
                return '';
            }

            if (in_array($key, $this->boolean)) {
                return (bool) $value;
            }

            return $value;
        });

        $array = [];
        foreach ($config as $key => $value) {
            array_set($array, $key, $value);
        }

        return $array;
    }
328898
public static function createFromArray(array $array): self
    {
        $map = new self;

        foreach ($array as $key => $value) {
            $map->put($key, $value);
        }

        return $map;
    }