Clean array before serialize to JSON

@param array $array
@return array
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;
    }
269952
public function copyToArray(array &$array)
    {
        $array['name']         = $this->name;
        $array['defaultEntry'] = $this->defaultEntry;
        $array['description']  = $this->description;
        $array['descriptions'] = LanguageUtility::convertArrayOfArrayCopyableToArray($this->descriptions);
        $array['attributes']   = LanguageUtility::convertArrayOfArrayCopyableToArray($this->attributes);
    }
1146570
static protected function flattenArray( $array )
    {
        if ( !is_array( $array ) )
        {
            return array( $array );
        }

        $arrayFlatten = array();
        while( !empty( $array ) )
        {
             $item = array_shift( $array );
             if ( is_array( $item ) )
                 $array = array_merge( $item, $array );
             else
                 $arrayFlatten[] = $item;
        }
        return $arrayFlatten;
    }
1221796
public static function encode( $array, $beautify = false ) 
	{	
		// php53 fix
		if ( defined( 'JSON_UNESCAPED_SLASHES' ) )
		{
			$json =  json_encode( $array, JSON_UNESCAPED_SLASHES );
		}
		else 
		{
			$json =  json_encode( $array );
		}
		
		if ( $beautify ) 
		{
			return static::beautify( $json );
		}
		
		return $json;
	}
942443
private function NormalizeArray($Array) {
      $Return = array();
      foreach ($Array as $Key => $Value) {
         if (is_array($Value) === TRUE && array_key_exists(0, $Value) === FALSE) {
            foreach($Value as $k => $v) {
               $Return[$Key.'.'.$k] = $v;
            }
         } else {
            $Return[$Key] = $Value;
         }
      }
      return $Return;
   }
547945
private function buildCleanParam($array)
    {
        $result = [];
        foreach ($array as $param => $paths) {
            foreach ($paths as $path) {
                $result[] = self::DIRECTIVE_CLEAN_PARAM . ':' . $param . ' ' . $path;
            }
        }
        return $result;
    }
914259
public static function writeArray($array)
    {
        $data = array();
        foreach ($array as $var=>$val) {
            if (is_array($val) && !is_object($val)) {
                $data[$var] = self::writeArray($val);
            } else {
                $data[$var] = self::writeArrayItem($val);
            }
        }
        return serialize($data);
    }
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;
    }
676324
public static function clean($array = null)
	{
		//check for the existance of the implementation class
		self::setImplmentationClass();

		//set the input parameters in a try...catch block for better error handling
		try {

			//set the value fo the $inputArray parameter
			$inputArray = ( ! is_null($array)) ? $array : self::$ArrayHelperClassInstance->getOutputElement();

			//check if input element was a null
			if($inputArray === null) throw new ArrayHelperException("NULL \$array value passed for removal of empty elements values to ArrayHelper::clean() method. A valid array is expected!", 1);

			//call the implementation class to clean the input array
			self::$ArrayHelperClassInstance->clean($inputArray);

			//return the static instance
			return new static;

		} 

		//catch the error messages here
		catch (ArrayHelperException $ArrayHelperExceptionInstance) {

			//diplay the error message
			$ArrayHelperExceptionInstance->errorShow();
			
		}

	}
1093868
static public function stringify(array $array)
    {
        $result = array();
        foreach ($array as $key => $value) {
            $result[] = sprintf('%s=%s', $key, $value);
        }
        return implode('&', $result);
    }
1000662
public static function trim_array($array)
    {

        if (empty($array) || !is_array($array)) return $array;

        foreach ($array as $key => $value) {
            $array[$key] = trim($value);
        }

        unset($key, $value);

        return $array;
    }
993468
private static function arrayToJson(array $phpArray) {
		$serializableValue = array();
		foreach ($phpArray as $key=>$val) {
			if ($val instanceof MoufInstanceDescriptor) {
				$value = $val->getIdentifierName();
			} else if (is_array($val)) {
				$value = self::arrayToJson($val);
			} else {
				$value = $val;
			}
				
			$serializableValue[] = array(
					"key" => $key,
					"value" => $value
			);
		}
		return $serializableValue;
	}
879211
public static function clean(array $objects) {
			foreach ($objects as $k => $obj) {
				$fields = self::getSObjectFields($obj);

				if ($fields === null) {
					unset($objects[$k]);

					continue;
				}

				foreach ($fields as $k => $v) {
					if ($v === null || is_string($v) && strlen($v) === 0) {
						if (!isset($obj->fieldsToNull))
							$obj->fieldsToNull = [];

						$obj->fieldsToNull[] = $k;

						unset($fields[$k]);

						continue;
					}

					$fields[$k] = $this->converter->convertForUpdateOrCreate($v);
				}

				$obj = self::updateSObjectFields($obj, $fields);
			}

			return $objects;
		}
1200967
protected function removeSlashes($array)
    {
        $fnc = function ($value) use (&$fnc) {
            if (is_array($value)) {
                return array_map($fnc, $value);
            }

            return stripslashes($value);
        };

        if (version_compare(phpversion(), '6.0.0-dev', '<') && get_magic_quotes_gpc()) {
            $array = array_map($fnc, $array);
        }

        return $array;
    }
680481
public static function convertStringToValueArray(array $array): array
    {

        foreach ($array as $i => $attr)
            $array[$i] = (is_array($attr) ? self::convertStringToValueArray($attr) : self::convertStringToValues($attr));

        return $array;
    }
326497
protected function arrayToObject(array $array)
    {
        $obj = (object) [];

        foreach ($array as $k => $v) {

            if (strlen($k)) {
                if (is_array($v)) {
                    $obj->{$k} = $this->arrayToObject($v);
                } else {
                    $obj->{$k} = $v;
                }
            }
        }

        return $obj;
    }
693262
public static function keyedArray($array) {
        if(is_array($array)) {
            $string = '[ ';
            foreach($array as $key => $item) {
                if(!is_string($item)) {
                    $item = self::keyedArray($item);
                }
                $string .= $key . ' => ' . $item;
                if($item !== last($array)) {
                    $string .= ', ';
                }
            }
            $string .= ' ]';

            return $string;
        } else {
            if(is_object($array)) {
                return get_class($array);
            } else {
                if(is_null($array)) {
                    return 'Null';
                } else {
                    return 'Unknown';
                }
            }
        }
    }