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;
    }
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;
    }
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 ; }
Clean array before serialize to JSON

@param array $array
@return array
Clean array before serialize to JSON