Print the 2D array in spiral order

Given a 2-dimensional array of integers, print the 2D array in spiral order.

For example:

A = [1,  2,  3,  4,
     5,  6,  7,  8,
     9,  10, 11, 12,
     13, 14, 15, 16]

Then spiral order output should be: [1, 2, 3, 4, 8, 12, 16, 15, 14, 13, 9, 5, 6, 7, 11, 10].