## Limited Time Offer!

For Less Than the Cost of a Starbucks Coffee, Access All DevOpsSchool Videos on YouTube Unlimitedly.
Master DevOps, SRE, DevSecOps Skills!

Enroll Now

## What is Associative Arrays?

Key value pairs are stored in associative arrays. For example, a numerically indexed array might not be the ideal choice for storing a student’s marks from several subjects in an array. Instead, we might use the names of the subjects as the keys in our associative array, with their appropriate marks as the value.

Example:-

Output:

### Some Features of Associative Arrays?

Associative arrays are similar to numeric arrays in appearance, but differ in terms of index. An associative array’s index is a string that establishes a strong relationship between key and value.

For storing employee wages in an array, a numerically indexed array is not the ideal choice. Instead, you may create an associative list with the workers’ names as keys and their salary as the value.

• The variable’s name is “\$variable name…”, the element’s access index number is “[‘key name’],” and the array element’s value is “value.”
• Consider the following scenario: you have a group of people and want to assign gender to each of them based on their names.
• You may achieve this by using an associative list.
• You can do so by using the code below.

#### Traversing the Associative Array:-

Loops may be used to go over associative arrays. The associative array can be looped through in two different ways. Using the for loop first, and then the foreach loop second.

Example:-

In this case, the array keys() function is used to identify indices with provided names, and the count() method is used to count the number of indices in associative arrays.

Output:-

Output:-

## Complete Tutorial of Numeric Array

### What is Numeric Array?

Numeric arrays allow us to store numerous values of the same data type in a single variable rather than creating multiple variables for each value. These values can then be accessed using an index, which is always a number in numeric arrays.

### How to declare and initialize an array?

There are two ways to create an array. Let’s take a look at both these ways in the Following example:

#### 1. Accessing the elements

You must know the index value of an array’s items in order to access them.

Example:-

#### 2. Length of an array

The in-built function `count `can be used to count the length of an array, or the number of elements in the array.

Example:-

## Complete Tutorial of Arrays

### What is Array?

Arrays are collections of data elements with a common name. Arrays provide a framework for defining and accessing several data elements with a single identity, making data administration easier.

When dealing with several data elements, we use array.

### How many types of Array?

• Numeric/Indexed Array:- In this array index will be represented by a number. By default numeric array index start from 0.
Example:-` \$num [0] = “ScmGalaxy”;`
• Associative Array:- In this Array index/key will be represented by a string.
Example:- `\$fees [“ScmGalaxy”] = 500;`
• Multidimensional Array:- Arrays of Arrays is known as multidimensional arrays.
Example:- `\$num [0] [0] = 25;`