What are the types of Array in PHP? Plz, provide an explanation with an example.

Types of PHP Arrays

There are 3 types of arrays in PHP.

  1. Indexed or Numeric Arrays
  2. Associative Arrays
  3. Multi-Dimensional Arrays

Indexed or Numeric Arrays

An index array is an array in which the values or items of the array are assigned by the index number. The name of the index array itself shows that the index number has importance in the index array. The index array has a different index number for each value. Index means 1, 2, 3, 4, 5 but index numbers in the index array start from 0. Index numbers are 0,1,2,3,4,etc.

$var = array("Value0", "Value1", "Value2");

Output

Associative Arrays

The associated array is a simple and very important array of PHP. This array is also used the most, it is also very easy to understand this array, as it contains keys and values. In simple language, the key acts as the name, and the value works as the information related to that name. For Mohan is a key and Mohan’s age or address, email, etc. are his values.

Example:-

Output

Multi-Dimensional Array

A multidimensional array is an array that uses more than one array, instead of storing a single element, it stores another array at each index.

Example:-

Output

Related Posts

PHP – strip_tags() Replace with Spaces Example

We are going to learn php strip tags with spaces. You will learn how to replace php Strip_tags with space. In this article, we will replace php…

How to Get Duplicate Values from Array in PHP?

We will learn php array get duplicate values. we will help you to give an example of how to get duplicate values from array in php. you…

PHP explode() Function Example Tutorial

A PHP explode function example is given in this article. I will demonstrate how to use PHP’s explode string to array function. This is a basic example…

How to Convert Array to String in PHP?

We will cover the example of converting an array to a string in PHP in this lesson. We’ll examine an example of converting an array to a…

How Can I Convert a String in PHP Into an Array?

We will go over how to transform a string into an array in PHP in this little tutorial. Describe how to convert a string value into an…

How to Use the array_merge() Function in PHP?

We will go over the simple and quick method to use the PHP array_merge() function example in this brief tutorial. Let’s talk about the PHP example of…

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x