Method to filter empty elements from XML

@param array $array

@return array
776918
public function arrayFilterRecursive(array $array)
    {
        foreach ($array as &$value) {
            if (is_array($value)) {
                /** @var $value array */
                $value = count($value) === 1 && array_key_exists(0, $value) && is_string($value[ 0 ]) &&
                $this->variable->isEmpty(trim($value[ 0 ])) ? $value[ 0 ] : $this->arrayFilterRecursive($value);
            }
        }

        return array_filter($array, function ($value) {
            return ! $this->variable->isEmpty($value) &&
                ! (is_string($value) && $this->variable->isEmpty(trim($value)));
        });
    }
840296
public static function simpleArrayToXml($array, $suppress_empty = false)
    {
        $xml = '';
        foreach ($array as $key => $value) {
            $value = trim($value, " ");
            if (empty($value) and (bool)$suppress_empty) {
                continue;
            }
            $htmlValue = htmlspecialchars($value, ENT_QUOTES, 'UTF-8');
            if ($htmlValue != $value) {
                $xml .= "\t" . "<$key>$htmlValue</$key>\n";
            } else {
                $xml .= "\t" . "<$key>$value</$key>\n";
            }
        }

        return $xml;
    }
923220
public function htmlAttributes($array)
    {
        if (!isset($array)) {
            return null;
        }
       
        $str = "";
        foreach ($array as $key => $value) {
            if (!isset($value) || $value === false) {
                continue;
            }
            
            if ($value === true) {
                $value = $key;
            }
            
            $str .= ' ' . $key . '="' . addcslashes($value, '"') . '"';
        }
        
        return trim($str);
    }
80521
public static function buildXml(&$xml, $array) {
		if (is_array($array)) {
			foreach ($array as $key => $value) {
				// XML_NONE
				if (!is_array($value)) {
					$xml->addChild($key, $value);
					continue;
				}

				// Multiple nodes of the same name
				if (isset($value[0])) {
					foreach ($value as $kValue) {
						if (is_array($kValue)) {
							self::buildXml($xml, array($key => $kValue));
						} else {
							$xml->addChild($key, $kValue);
						}
					}

				// XML_GROUP
				} else if (isset($value['attributes'])) {
					if (is_array($value['value'])) {
						$node = $xml->addChild($key);
						self::buildXml($node, $value['value']);
					} else {
						$node = $xml->addChild($key, $value['value']);
					}

					if (!empty($value['attributes'])) {
						foreach ($value['attributes'] as $aKey => $aValue) {
							$node->addAttribute($aKey, $aValue);
						}
					}

				// XML_MERGE
				} else if (isset($value['value'])) {
					$node = $xml->addChild($key, $value['value']);
					unset($value['value']);

					if (!empty($value)) {
						foreach ($value as $aKey => $aValue) {
							if (is_array($aValue)) {
								self::buildXml($node, array($aKey => $aValue));
							} else {
								$node->addAttribute($aKey, $aValue);
							}
						}
					}

				// XML_OVERWRITE
				} else {
					$node = $xml->addChild($key);

					if (!empty($value)) {
						foreach ($value as $aKey => $aValue) {
							if (is_array($aValue)) {
								self::buildXml($node, array($aKey => $aValue));
							} else {
								$node->addChild($aKey, $aValue);
							}
						}
					}
				}
			}
		}

		return $xml;
	}
77898
public static function removeElement(array $array, $item)
    {
        /*
         * No elements or the element does not exist?
         * Nothing to do
         */
        if (empty($array) || !in_array($item, $array, true)) {
            return false;
        }

        // Flip the array to make it looks like: value => key
        $arrayFlipped = array_flip($array);

        // Take the key of element / item that should be removed
        $key = $arrayFlipped[$item];

        // ...and remove the element / item
        unset($array[$key]);

        return $array;
    }
1057578
private function getArrayValues($array)
    {
        $out = [];
        $it = new \RecursiveIteratorIterator(new \RecursiveArrayIterator($array));

        foreach ($it as $value) {
            $out[] = $value;
        }
        return $out;
    }
403033
private function filterElements(array $elements): array
    {
        $filteredElements = [];

        foreach ($elements as $element) {
            if (!$this->elementExcluder->isExcluded($element) && $this->hasUrlAttribute($element)) {
                $filteredElements[] = $element;
            }
        }

        return $filteredElements;
    }
223895
public static function filter(array $array, callable $callable = NULL) {
    $array = is_callable($callable) ? array_filter($array, $callable) : array_filter($array);
    foreach ($array as &$element) {
      if (is_array($element)) {
        $element = static::filter($element, $callable);
      }
    }

    return $array;
  }
603318
public function removeEmpty(array $empty = [false, null, ''])
    {
        return $this->filter(function ($item) use ($empty) {
            return !in_array($item, $empty, true);
        });
    }
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;
    }
1065925
public static function filterArray($array)
    {
        if (!is_array($array))
        {
            return false;
        }

        $clean = array();
        foreach ($array as $key => $string)
        {
            if (is_array($string))
            {
                self::filterArray($string);
            }
            else
            {
                $string = self::escape($string);
                $key = self::escape($key);
            }
            $clean[$key] = $string;
        }
        return $clean;
    }
955667
protected function convertXmlObjectToArray($xml)
    {
        $array = (array) $xml;

        if (count($array) == 0 && ! is_array($xml)) {

            $array = [ (string) $xml ];
        }

        if (is_array($array)) {

            foreach ($array as $key => $value) {

                if (is_object($value)) {

                    if (strpos(get_class($value), "SimpleXML") !== false) {

                        $array[ $key ] = $this->convertXmlObjectToArray($value);

                    } else {

                        $array[ $key ] = $this->convertXmlObjectToArray( (array) $value );
                    }

                } elseif (is_array($value)) {

                    $array[ $key ] = $this->convertXmlObjectToArray($value);
                }
            }
        }

        return $array;
    }
273990
public static function stripNonInteger(array $array): array {
        $newArray = [];
        foreach ($array as $value) {
            if (!NumberUtil::isInteger($value)) continue;
            $newArray[] = \intval($value);
        }
        return $newArray;
    }
337076
public static function array_flatten(array $array){
		$index = 0;
		$count = count($array);

		while ($index < $count) {
			if (is_array($array[$index])) {
				array_splice($array, $index, 1, $array[$index]);
			} else {
				++$index;
			}
			$count = count($array);
		}
		return $array;
	}
1310871
public static function getIndexOf(array $array, $element)
    {
        // No elements?
        // Nothing to do
        if (empty($array)) {
            return false;
        }

        foreach ($array as $index => $value) {
            if ($value === $element) {
                return $index;
            }
        }

        return null;
    }
499989
private function fromArrayToXmlString(array $array)
    {
        $string = '';

        foreach ($array as $key => $value) {
            $string .= '<' . $key . '>' .
                ((is_array($value))
                    ? $this->fromArrayToXmlString($value)
                    : $value) .
                '</' . $key . '>';
        }

        return $string;
    }
1348608
public function filterArray($array)
    {
        $newArray = array();

        foreach ($array as $key => $row) {
            foreach ($this->columnToFilter as $column) {
                if (!array_key_exists($column, $row)) {
                    continue;
                }

                if (self::match($this->patternToSearchQuoted, $row[$column], $this->invertedMatch)) {
                    $newArray[$key] = $row;
                    continue 2;
                }
            }
        }

        return $newArray;
    }