Go language supports multi-dimensional arrays. The following is the commonly used multi-dimensional array declaration method:
var variable_name [SIZE1][SIZE2]...[SIZEN] variable_type
Two-dimensional array
二A two-dimensional array is the simplest multi-dimensional array. A two-dimensional array is essentially composed of a one-dimensional array. The two-dimensional array is defined as follows:
var arrayName [ x ][ y ] variable_type
variable_type is the data type of the Go language, arrayName is the array name, and the two-dimensional array can be considered as a table, x is the row, and y is the column.
Initializing a two-dimensional array
Multi-dimensional arrays can be initialized through braces. The following example is a two-dimensional array with 3 rows and 4 columns:
a = [3][4]int{ {0, 1, 2, 3} , /* 第一行索引为 0 */ {4, 5, 6, 7} , /* 第二行索引为 1 */ {8, 9, 10, 11}, /* 第三行索引为 2 */ }
For more golang knowledge, please pay attention to the golang tutorial column on the PHP Chinese website.
The above is the detailed content of How to define a two-dimensional array in golang. For more information, please follow other related articles on the PHP Chinese website!