Recursively removes empty array elements.

@param array $array
@return array the modified array
351467
public static function removeEmptyElementsRecursively(array $array): array
    {
        $result = $array;
        foreach ($result as $key => $value) {
            if (is_array($value)) {
                $result[$key] = self::removeEmptyElementsRecursively($value);
                if ($result[$key] === []) {
                    unset($result[$key]);
                }
            } elseif ($value === null) {
                unset($result[$key]);
            }
        }
        return $result;
    }
921694
public function clean($array)
	{
		//set the $inputElement
		$this->inputElement = $array;

		//loop throught the input array removing empty elements and return resultant array
		$this->outputElement = array_values(array_filter($array, function($item){

				return ! empty($item);

		}));

		//return this self same class
		return $this;

	}
392515
protected function filterArray(array $array): array
	{
		$newArray = [];

		foreach($array as $row)
		{
			$newArray[] =  (is_array($row)) ? $row[0] : $row;
		}

		return $newArray;
	}
585365
public function sort(array $array): array {
        $array = \array_values($array);
        $length = \count($array);

        if (0 === $length || 1 === $length) return $array;

        for ($i = 0; $i < $length; $i++) {
            $min = $i;
            for ($j = $i; $j < $length; $j++) {
                if (Comparator::lessThan($array[$j], $array[$min])) {
                    $min = $j;
                }
            }
            $tmp = $array[$min];
            $array[$min] = $array[$i];
            $array[$i] = $tmp;
        }
        return $array;
    }
1357246
public static function unsetFields($array, $fields = null)
    {
        if (!is_array($array)) {
            $fields = [];
        }
        foreach ($array as $key => $value) {
            if (is_string($key) && in_array($key, $fields)) {
                unset($array[$key]);
            }
        }
        return $array;
    }
1235366
public static function flatten($array)
    {
        if (!is_array($array)) {
            // nothing to do if it's not an array
            return array($array);
        }

        $result = array();
        foreach ($array as $value) {
            // explode the sub-array, and add the parts
            $result = array_merge($result, static::flatten($value));
        }

        return $result;
    }
1085625
protected function doReplacements( array $array ) {
		$args = [
			$this[ Argument::NAMES ][ Name::SINGULAR_NAME_UC ],
			$this[ Argument::NAMES ][ Name::SINGULAR_NAME_LC ],
			$this[ Argument::NAMES ][ Name::PLURAL_NAME_UC ],
			$this[ Argument::NAMES ][ Name::PLURAL_NAME_LC ],
		];

		foreach ( $array as $key => $string ) {
			$array[ $key ] = sprintf( $string, ...$args );
		}

		return $array;
	}
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;
    }
1357308
public static function removeElementsFromArray($elements, &$array)
    {
        if (!is_array($elements))
        {
            $elements = [$elements];
        }
        $length = count($array);
        for ($i = 0; $i < $length; $i++)
        {
            $exist = false;
            foreach ($elements as $element)
            {
                if ($array[$i] == $element)
                {
                    $exist = true;
                    break;
                }
            }
            if ($exist)
            {
                unset($array[$i]);
            }
        }
        $array = array_values($array);
    }
1280222
private function cleanArray(array $array = [], $replaceWith)
    {
        $dirtyKeys = $this->findBadWordsInArray($array);

        foreach ($dirtyKeys as $key) {

            $this->cleanArrayKey($key, $array, $replaceWith);
        }

        return $array;
    }
300871
public static function REMOVE_EMPTY( array $data)
	{
		$a = array();
	    foreach ($data as $key => $value) {
	       $a[$key] = is_array($value)?array_filter($value):$value;
	    }
	    return array_filter($a);
	}
232415
private function _flatten($array)
    {
        if (!is_array($array)) {
            // nothing to do if it's not an array
            return array($array);
        }
        $result = array();
        foreach ($array as $value) {
            // explode the sub-array, and add the parts
            $result = array_merge($result, $this->_flatten($value));
        }
        return $result;
    }
162994
public static function flat(array $array)
    {
        $out = [];
        foreach ($array as $key=>$value) {
            if (is_array($value)) {
                //use recursion to get to the next array
                $out = array_merge($out, self::flat($value));
            } else {
                //add the value to the back of the array
                //if the value is not an array
                $out[] = $value;
            }
        }
        //return the resulting array
        return $out;
    }
1044584
public static function trimRecursive(array $array)
    {
        /*
         * No elements?
         * Nothing to do
         */
        if (empty($array)) {
            return [];
        }

        $result = [];

        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $result[$key] = self::trimRecursive($value);

                continue;
            }

            if (is_string($value)) {
                $value = trim($value);
            }

            $result[$key] = $value;
        }

        return $result;
    }
574720
protected function fixEmptyRelationArrays(array &$array)
    {
        $activeKey = '';
        if (array_key_exists('rlt', $array)) {
            $activeKey = 'rlt';
        }
        if (array_key_exists('relations', $array)) {
            $activeKey = 'relations';
        }

        if (! $activeKey) {
            return;
        }

        $relations = $array[$activeKey];

        if ($relations) {
            foreach ($relations as $name => $jory) {
                if (empty($jory)) {
                    $array[$activeKey][$name] = new \stdClass();
                } else {
                    $this->fixEmptyRelationArrays($jory);
                }
            }
        }
    }
549461
public static function cleanBeforeJson(array $array): array
    {
        foreach ($array as $key => $value) {
            if (is_array($value)) {
                $array[$key] = self::cleanBeforeJson($array[$key]);
            }

            if ($array[$key] === '' || null === $array[$key]) {
                unset($array[$key]);
            }
        }

        return $array;
    }
3309
public static function remove(&$array, $keys)
    {
        $original = &$array;
        $keys     = (array) $keys;

        if (!Arr::accessible($array)) {
            return;
        }
        if (count($keys) === 0) {
            return;
        }

        foreach ($keys as $key) {
            if (Arr::exists($array, $key)) {
                unset($array[$key]);

                continue;
            }

            // Clean up before each pass
            $array = &$original;
            $parts = explode('.', $key);

            while (count($parts) > 1) {
                $part = array_shift($parts);
                if (isset($array[$part]) && is_array($array[$part])) {
                    $array = &$array[$part];
                } else {
                    continue 2;
                }
            }

            unset($array[array_shift($parts)]);
        }
    }