logo

Hoe waarde in array op te slaan

Een array is een groep van vergelijkbare typen elementen met een aangrenzende geheugenlocatie. Een array is een verzameling variabelen van hetzelfde type die met een algemene naam worden aangeduid.

In deze tutorial wordt kort uitgelegd hoe u waarde in een array kunt opslaan in de veelgebruikte talen.

1. C Taal

Alle arrays vormen het aaneengesloten blok geheugenlocaties. Standaard slaat de laagste positie van de array het eerste element op, en de hoogste positie de laatste gegevens. In C wordt de array gedeclareerd door het type van het element en de totale lengte van de array die nodig is om de gegevens op te slaan, op te geven.

Syntaxis voor het declareren van array

 type arrayName [ arrSize ]; 

Syntaxis voor initialisatie voor het opslaan van arraywaarden

 double balance[6] = {500.0, 52.0, 63.6, 77.80, 70.10, 80.12}; 

Voorbeeld

 #include int main () { int n[ 11 ]; /* declaring an array comprising of 11 integers */ int i,j; /* initialize elements of array n to 0 */ for ( i = 0; i <11; 100 i++ ) { n[ i ]="i" + 10; * storing or initializing the array at location with element } result of element's value for (j="0;" j < 11; j++ printf('element stored position [%d]="%d
&apos;," j, n[j] ); return 0; pre> <p> <strong>Output</strong> </p> <pre> Element stored at position [0] = 10 Element stored at position [1] = 11 Element stored at position [2] = 12 Element stored at position [3] = 13 Element stored at position [4] = 14 Element stored at position [5] = 15 Element stored at position [6] = 16 Element stored at position [7] = 17 Element stored at position [8] = 18 Element stored at position [9] = 19 Element stored at position [10] = 20 </pre> <h3>Multidimensional Array in C</h3> <p>In C language, the elements of a 2 D (two-dimensional) array are accessed with the help of subscripts, i.e., the row index number and the column index number of the array.</p> <p> <strong>Syntax for declaring Array</strong> </p> <pre> int val = arr[x][y]; </pre> <p> <strong>Syntax for Initializing Two-Dimensional Arrays</strong> </p> <pre> int a[1][4] = { {4, 4, 2, 1} , /* initializers for row indexed by 0 */ {4, 5, 16, 10} , /* initializers for row indexed by 1 */ {8, 19, 10, 11} /* initializers for row indexed by 2 */ }; </pre> <p> <strong></strong> </p> <pre> #include int main () { /* declaring and initializing the array with 4 rows and 2 columns*/ int arr[4][2] = { {1,0}, {1,2}, {2,4}, {3,6}}; int i, j; /* output each array element&apos;s value */ for ( i = 0; i <4; i++ ) { for ( j="0;" < 2; j++ printf(' data stored in 2d array[%d][%d]="%d
&apos;," i,j, arr[i][j] ); } return 0; pre> <p> <strong>Output</strong> </p> <pre> Data stored in 2D array[0][0] = 1 Data stored in 2D array[0][1] = 0 Data stored in 2D array[1][0] = 1 Data stored in 2D array[1][1] = 2 Data stored in 2D array[2][0] = 2 Data stored in 2D array[2][1] = 4 Data stored in 2D array[3][0] = 3 Data stored in 2D array[3][1] = 6 </pre> <h2>2. C++ Language</h2> <p>In C++ language the user needs to specify the element type and total length of array.</p> <p> <strong>Syntax to Declare Array</strong> </p> <pre> type arrName [ arrSize ]; </pre> <p> <strong>Syntax to initialize array</strong> </p> <pre> int arr[] = { 1, 2, 3, 4, 5 } </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows. int arr[4] = {1,7,50,6}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) { cout << 'array at position[' i ']: '; arr[i]<< endl; } return 0; < pre> <p> <strong>Output</strong> </p> <pre> array at position[0]: 1 array at position[1]: 7 array at position[2]: 50 array at position[3]: 6 </pre> <h3>Multidimensional Array</h3> <p>C++ language also enables the Multidimensional arrays.</p> <p> <strong>Syntax for initializing 2D array</strong> </p> <pre> int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << 'array at position[' i '][' ']: '; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println('element at ' + i : arr[i].id_no +' '+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + ' '); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks['Reema ']='95'; $marks['John']='45'; $marks ['Rahul ']='20'; echo 'Reema's Marks: '.$marks ['Reema '].' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,'Reema',95), array(2,'john',45), array(3,'rahul',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].' '; } echo ' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;></pre></4;></pre></4;></pre></11;>

Multidimensionale array in C

In de C-taal zijn de elementen van een 2D (tweedimensionale) array toegankelijk met behulp van subscripts, dat wil zeggen het rij-indexnummer en het kolomindexnummer van de array.

Syntaxis voor het declareren van Array

 int val = arr[x][y]; 

Syntaxis voor het initialiseren van tweedimensionale arrays

 int a[1][4] = { {4, 4, 2, 1} , /* initializers for row indexed by 0 */ {4, 5, 16, 10} , /* initializers for row indexed by 1 */ {8, 19, 10, 11} /* initializers for row indexed by 2 */ }; 

 #include int main () { /* declaring and initializing the array with 4 rows and 2 columns*/ int arr[4][2] = { {1,0}, {1,2}, {2,4}, {3,6}}; int i, j; /* output each array element&apos;s value */ for ( i = 0; i <4; i++ ) { for ( j="0;" < 2; j++ printf(\' data stored in 2d array[%d][%d]="%d
&apos;," i,j, arr[i][j] ); } return 0; pre> <p> <strong>Output</strong> </p> <pre> Data stored in 2D array[0][0] = 1 Data stored in 2D array[0][1] = 0 Data stored in 2D array[1][0] = 1 Data stored in 2D array[1][1] = 2 Data stored in 2D array[2][0] = 2 Data stored in 2D array[2][1] = 4 Data stored in 2D array[3][0] = 3 Data stored in 2D array[3][1] = 6 </pre> <h2>2. C++ Language</h2> <p>In C++ language the user needs to specify the element type and total length of array.</p> <p> <strong>Syntax to Declare Array</strong> </p> <pre> type arrName [ arrSize ]; </pre> <p> <strong>Syntax to initialize array</strong> </p> <pre> int arr[] = { 1, 2, 3, 4, 5 } </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows. int arr[4] = {1,7,50,6}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) { cout << \'array at position[\' i \']: \'; arr[i]<< endl; } return 0; < pre> <p> <strong>Output</strong> </p> <pre> array at position[0]: 1 array at position[1]: 7 array at position[2]: 50 array at position[3]: 6 </pre> <h3>Multidimensional Array</h3> <p>C++ language also enables the Multidimensional arrays.</p> <p> <strong>Syntax for initializing 2D array</strong> </p> <pre> int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << \'array at position[\' i \'][\' \']: \'; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;></pre></4;></pre></4;>

2. C++ Taal

In de C++-taal moet de gebruiker het elementtype en de totale lengte van de array opgeven.

Syntaxis voor het declareren van array

 type arrName [ arrSize ]; 

Syntaxis om array te initialiseren

 int arr[] = { 1, 2, 3, 4, 5 } 

Voorbeeld

 #include using namespace std; int main () { // declaring an array with 4 rows. int arr[4] = {1,7,50,6}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) { cout << \'array at position[\' i \']: \'; arr[i]<< endl; } return 0; < pre> <p> <strong>Output</strong> </p> <pre> array at position[0]: 1 array at position[1]: 7 array at position[2]: 50 array at position[3]: 6 </pre> <h3>Multidimensional Array</h3> <p>C++ language also enables the Multidimensional arrays.</p> <p> <strong>Syntax for initializing 2D array</strong> </p> <pre> int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; </pre> <p> <strong>Example</strong> </p> <pre> #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << \'array at position[\' i \'][\' \']: \'; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;></pre></4;>

Multidimensionale array

C++-taal maakt ook de multidimensionale arrays mogelijk.

Syntaxis voor het initialiseren van 2D-array

 int a[4][3] = { {0, 1, 2} , /* storing data in array for row indexed by 0 */ {42, 25, 62} , /* storing data in array for row indexed by 1 */ {18, 90, 15}, /* storing data in array for row indexed by 2 */ {21, 19, 25}, /* storing data in array for row indexed by 3 */ }; 

Voorbeeld

Java-teken naar string
 #include using namespace std; int main () { // declaring an array with 4 rows and 2 columns. int arr[4][2] = { {1,0}, {0,2}, {2,3}, {5,6}}; // traversing the output for each array value for ( int i = 0; i <4; i++ ) for ( int j="0;" < 2; j++ { cout << \'array at position[\' i \'][\' \']: \'; arr[i][j]<< endl; } return 0; pre> <p> <strong>Output</strong> </p> <pre> array at position[0][0]: 1 array at position[0][1]: 0 array at position[1][0]: 0 array at position[1][1]: 2 array at position[2][0]: 2 array at position[2][1]: 3 array at position[3][0]: 5 array at position[3][1]: 6 </pre> <h2>3. Java</h2> <p>In Java language, Arrays work differently than what they used to do in C or C++ language.</p> <h3>One-Dimensional Arrays:</h3> <p>To declare an array, the user needs to have two primary components: the type and the array&apos;s name.</p> <p>The &apos;Type&apos; refers to the elementary type of a specific array. It determines the data type of all elements that are included in the array. It comprises the array of primitive data types, unlike integers, char, float, double, etc., or it could include the user-defined data types (objects of a class) as well. Therefore, the element type for the array concludes what kind of data the array will contain.</p> <p> <strong>Syntax</strong> </p> <pre> type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; </pre> <p> <strong>Store values in one-dimensional array</strong> </p> <p>Assigning values to an element in an array is similar to assigning values to scalar variables.</p> <pre> Array [index]= initializers; arr[1]= 50 arr[2]= 20 </pre> <h4>NOTE: It the array element is not assigned any value, by default it has a Null (empty) value.</h4> <p> <strong>Example</strong> </p> <pre> //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)></pre></4;>

3. Java

In de Java-taal werken Arrays anders dan wat ze vroeger deden in de C- of C++-taal.

Eendimensionale arrays:

Om een ​​array te declareren, heeft de gebruiker twee primaire componenten nodig: het type en de naam van de array.

Het 'Type' verwijst naar het elementaire type van een specifieke array. Het bepaalt het gegevenstype van alle elementen die in de array zijn opgenomen. Het omvat de reeks primitieve gegevenstypen, in tegenstelling tot gehele getallen, char, float, double, enz., of het kan ook de door de gebruiker gedefinieerde gegevenstypen (objecten van een klasse) omvatten. Daarom concludeert het elementtype voor de array welk soort gegevens de array zal bevatten.

Syntaxis

 type arr_var_name[]; OR type[] arr_var_name; OR var-name = new type [size]; 

Bewaar waarden in een eendimensionale array

Het toewijzen van waarden aan een element in een array is vergelijkbaar met het toewijzen van waarden aan scalaire variabelen.

 Array [index]= initializers; arr[1]= 50 arr[2]= 20 

OPMERKING: Als aan het array-element geen waarde is toegewezen, heeft het standaard een Null (lege) waarde.

Voorbeeld

 //Java Program to demonstrate how to initialize, store and display //values in one-dimensional arrays. class Testarray{ public static void main(String args[]){ int arr[]=new int[5];//declaration and instantiation arr[0]=20;//initialization of the array arr[1]=40; arr[2]=60; arr[3]=80; arr[4]=100; //traversing array to print the array values for(int i=0;i <arr.length;i++) system.out.println(arr[i]); }} < pre> <p> <strong>Output</strong> </p> <pre> 20 40 60 80 100 </pre> <h3>Arrays of Objects</h3> <p>An array of objects is constructed in the same way as an array of primitive type data elements.</p> <p> <strong>Example</strong> </p> <pre> // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\'element at \' + i : arr[i].id_no +\' \'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \' \'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\'Reema \']=\'95\'; $marks[\'John\']=\'45\'; $marks [\'Rahul \']=\'20\'; echo \'Reema\'s Marks: \'.$marks [\'Reema \'].\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\'Reema\',95), array(2,\'john\',45), array(3,\'rahul\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\' \'; } echo \' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;></pre></arr.length;i++)>

Arrays van objecten

Een array van objecten wordt op dezelfde manier geconstrueerd als een array van gegevenselementen van het primitieve type.

Voorbeeld

 // Java program to create, store and display values for one-dimensional // array of objects class Employee { public int id_no; public String name; Employee(int id_no, String name) { this.id_no = id_no; this.name = name; } } // The Elements of the array are objects of a class Employee. public class Array_Objects_Example { public static void main (String[] args) { // declares an Array of integers. Employee[] arr; // assigning space for 5 objects of type Employee. arr = new Employee[5]; // storing the value for the first element of the array arr[0] = new Employee(111,&apos;Varun&apos;); // storing the value for the second elements of the array arr[1] = new Employee(121,&apos;Sukla&apos;); // so on... arr[2] = new Employee(131,&apos;Virat&apos;); arr[3] = new Employee(141,&apos;Anuskha&apos;); arr[4] = new Employee(151,&apos;Mohit&apos;); // accessing the elements of the specified array for (int i = 0; i <arr.length; i++) system.out.println(\\'element at \\' + i : arr[i].id_no +\\' \\'+ arr[i].name); } < pre> <p> <strong>Output</strong> </p> <pre> Element at 0 : 111 Varun Element at 1 : 121 Sukla Element at 2 : 131 Virat Element at 3 : 141 Anuskha Element at 4 : 151 Mohit </pre> <h3>Multidimensional Arrays</h3> <p>Multidimensional arrays are termed &apos;arrays of arrays&apos; as they can hold each element of an array with the reference of another array. These are also known as Jagged Arrays. A multidimensional array is constructed by adding a set of square brackets ([]) per dimension.</p> <p> <strong>Syntax</strong> </p> <pre> int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array </pre> <p> <strong>Example to store values in a Multidimensional Array</strong> </p> <pre> arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; </pre> <p> <strong>Example of Multidimensional Array</strong> </p> <pre> class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \\' \\'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\\'Reema \\']=\\'95\\'; $marks[\\'John\\']=\\'45\\'; $marks [\\'Rahul \\']=\\'20\\'; echo \\'Reema\\'s Marks: \\'.$marks [\\'Reema \\'].\\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\\'Reema\\',95), array(2,\\'john\\',45), array(3,\\'rahul\\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\\' \\'; } echo \\' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3></pre></arr.length;>

Multidimensionale arrays

Multidimensionale arrays worden 'arrays van arrays' genoemd, omdat ze elk element van een array kunnen bevatten met de referentie van een andere array. Deze worden ook wel Jagged Arrays genoemd. Een multidimensionale array wordt geconstrueerd door een reeks vierkante haken ([]) per dimensie toe te voegen.

Syntaxis

 int[][] intArray = new int[10][20]; //a 2D array or matrix int[][][] intArray = new int[10][20][10]; //a 3D array 

Voorbeeld om waarden op te slaan in een multidimensionale array

 arry[0][0]=10; arry[0][1]=20; arry[0][2]=30; arry[1][0]=40; arry[1][1]=50; arry[1][3]=60; arry[2][1]=70; arry[2][2]=80; arry[2][3]=90; 

Voorbeeld van een multidimensionale array

 class multiDimensional_Example { public static void main(String args[]) { // declaring and storing data in 2-Dimensional array int arry[][] = { {12,17,19},{32,62,12},{37,34,32} }; // traversing and printing the 2-Dimensional array for (int i=0; i<3 3 ; i++) { for (int j="0;" < j++) system.out.print(arry[i][j] + \\' \\'); system.out.println(); } pre> <p> <strong>Output</strong> </p> <pre> 12 17 19 32 62 12 37 34 32 </pre> <h2>4. PHP</h2> <p>PHP array is an ordered map (holds elements on the base of the key-value). It is utilized to hold multiple values of a similar data type in a single variable.</p> <p>PHP contains 3 kinds of array that are as follows:</p> <ol class="points"> <li>Indexed Array</li> <li>Associative Array</li> <li>Multidimensional Array</li> </ol> <h3>1. Indexed Array</h3> <p>PHP index is described by an integer number that begins with 0 (default value). The PHP array can store any data type, such as numbers, characters, strings, and objects. All PHP array data are allocated an index number by default.</p> <p> <strong>Syntax to store values</strong> </p> <pre> $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; </pre> <p> <strong>Example</strong> </p> <pre> </pre> <p> <strong>Output</strong> </p> <pre> Colours are: Red, White, Black, Yellow </pre> <h3>2. Associative Array</h3> <p>In PHP, the user can associate any specific name with each array elements using the &apos;=&gt;&apos; symbol.</p> <p> <strong>Syntax</strong> </p> <pre> $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); </pre> <p> <strong>Or</strong> </p> <pre> $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; </pre> <p> <strong>Example</strong> </p> <pre> <?php $marks[\\'Reema \\']=\\'95\\'; $marks[\\'John\\']=\\'45\\'; $marks [\\'Rahul \\']=\\'20\\'; echo \\'Reema\\'s Marks: \\'.$marks [\\'Reema \\'].\\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 </pre> <h3>3. Multidimensional Array</h3> <p>Multidimensional arrays in PHP are also termed as &apos;array of arrays&apos;. It enabled the user to store array data in a tabular format. PHP multidimensional array can be expressed in the form of a matrix which is denoted by row * column.</p> <p> <strong>Syntax</strong> </p> <pre> $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); </pre> <p> <strong>Example</strong> </p> <pre> <?php $emp = array ( array (1,\\'Reema\\',95), array(2,\\'john\\',45), array(3,\\'rahul\\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\\' \\'; } echo \\' <br/>&apos;; } ?&gt; </pre> <p> <strong>Output</strong> </p> <pre> 1 Reema 95 2 john 45 3 rahul 20 </pre> <h2>5. Python</h2> <p>Python uses a module named &apos;Array&apos; to handle all the functions of Arrays in Python. It is helpful when the user wants to manipulate only particular data values. Given below are the keywords that are important to learn the concept of an array in Python:</p> <ul> <li>Element - Any data stored in an array is known an element.</li> <li>Index - Whenever an array stores any data, it has some numerical location known as index that is beneficial to identify the location of the element.</li> </ul> <p> <strong>Syntax</strong> </p> <pre> from array import * arrayName = array(typecode, [data_to_be_initialized]) </pre> <p> <strong>Example</strong> </p> <pre> import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) </pre> <p> <strong>Output</strong> </p> <pre> First array value: 20 Second array value: 40 Second last array value: 80 </pre> <hr></3>

4. PHP

PHP-array is een geordende kaart (bevat elementen op de basis van de sleutelwaarde). Het wordt gebruikt om meerdere waarden van een vergelijkbaar gegevenstype in één variabele vast te houden.

PHP bevat 3 soorten arrays die als volgt zijn:

  1. Geïndexeerde array
  2. Associatieve array
  3. Multidimensionale array

1. Geïndexeerde array

De PHP-index wordt beschreven door een geheel getal dat begint met 0 (standaardwaarde). De PHP-array kan elk gegevenstype opslaan, zoals cijfers, tekens, tekenreeksen en objecten. Alle PHP-arraygegevens krijgen standaard een indexnummer toegewezen.

Syntaxis om waarden op te slaan

 $Colour =array(&apos;Red&apos;, &apos;White&apos;, &apos;Black&apos;, &apos;Yellow&apos;); 

Of

 $Colour[0]=&apos;Red &apos;; $Colour[1]=&apos;White&apos;; $Colour[2]=&apos;Black&apos;; $Colour[3]=&apos;Yellow&apos;; 

Voorbeeld

 

Uitvoer

waar is de sleutel op het toetsenbord van de laptop
 Colours are: Red, White, Black, Yellow 

2. Associatieve array

In PHP kan de gebruiker elke specifieke naam aan elk array-element koppelen met behulp van het '=>'-symbool.

Syntaxis

 $marks =array(&apos;Reema&apos;=&gt;&apos;95&apos;,&apos;John&apos;=&gt;&apos;45&apos;,&apos;Rahul&apos;=&gt;&apos;20&apos;); 

Of

 $marks[&apos;Reema &apos;]=&apos;95&apos;; $marks[&apos;John&apos;]=&apos;45&apos;; $marks [&apos;Rahul &apos;]=&apos;20&apos;; 

Voorbeeld

 <?php $marks[\\'Reema \\']=\\'95\\'; $marks[\\'John\\']=\\'45\\'; $marks [\\'Rahul \\']=\\'20\\'; echo \\'Reema\\'s Marks: \\'.$marks [\\'Reema \\'].\\' <br/>&apos;; echo &apos; John&apos;s Marks: &apos;.$marks[&apos;John&apos;].&apos; <br>&apos;; echo &apos; Rahul&apos;s Marks: &apos;.$marks [&apos;Rahul &apos;].&apos; <br>&apos;; ?&gt; 

Uitvoer

 Reema&apos;s Marks: 95 John&apos;s Marks: 45 Rahul&apos;s Marks: 20 

3. Multidimensionale array

Multidimensionale arrays in PHP worden ook wel 'array of arrays' genoemd. Het stelde de gebruiker in staat arraygegevens in tabelvorm op te slaan. De multidimensionale PHP-array kan worden uitgedrukt in de vorm van een matrix die wordt aangegeven met rij * kolom.

Syntaxis

 $emp = array ( array (1,&apos;Reema&apos;,95), array(2,&apos;john&apos;,45), array(3,&apos;rahul&apos;,20) ); 

Voorbeeld

 <?php $emp = array ( array (1,\\'Reema\\',95), array(2,\\'john\\',45), array(3,\\'rahul\\',20) ); for ($row = 0; $row < 3; $row++) { for ($col = 0; $col < 3; $col++) { echo $emp[$row][$col].\\' \\'; } echo \\' <br/>&apos;; } ?&gt; 

Uitvoer

 1 Reema 95 2 john 45 3 rahul 20 

5. Python

Python gebruikt een module met de naam 'Array' om alle functies van arrays in Python af te handelen. Dit is handig als de gebruiker alleen bepaalde gegevenswaarden wil manipuleren. Hieronder staan ​​de sleutelwoorden die belangrijk zijn om het concept van een array in Python te leren:

  • Element - Alle gegevens die in een array zijn opgeslagen, staan ​​bekend als een element.
  • Index - Wanneer een array gegevens opslaat, heeft deze een numerieke locatie die bekend staat als index en die nuttig is om de locatie van het element te identificeren.

Syntaxis

 from array import * arrayName = array(typecode, [data_to_be_initialized]) 

Voorbeeld

 import array as arry n = arry.array(&apos;i&apos;, [20, 40, 60, 80]) print(&apos;First array value:&apos;, n[0]) print(&apos;Second array value:&apos;, n[1]) print(&apos;Second last array value:&apos;, n[-1]) 

Uitvoer

 First array value: 20 Second array value: 40 Second last array value: 80