input: Write a python function to print a 2D array in spiral order.
  assert spiral_order([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) == "1 2 3 6 9 8 7 4 5"
  assert spiral_order([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12], [13, 14, 15, 16]]) == "1 2 3 4 8 12 16 15 14 13 9 5 6 7 11 10"
  assert spiral_order([[1, 2], [3, 4]]) == "1 2 4 3"
  assert spiral_order([[1]]) == "1"
  assert spiral_order([]) == ""
output: def spiral_order(matrix):
      if not matrix:
          return ""
      
      result = []
      while matrix:
          # Take the first row
          result += matrix.pop(0)
          # Take the last element from remaining rows
          if matrix and matrix[0]:
              for row in matrix:
                  result.append(row.pop())
          # Take the last row in reverse order
          if matrix:
              result += matrix.pop()[::-1]
          # Take the first element from remaining rows in reverse order
          if matrix and matrix[0]:
              for row in matrix[::-1]:
                  result.append(row.pop(0))
                  
      return " ".join(map(str, result))