Array in PHP | Types Of Array with Examples

Hello Friend how are you i hope you all are doing well. Today in this post we will learn about Array in PHP like what is Array, Syntax of Array, Initialization of Array, Types of Array with examples. If you want to learn PHP in very simple easy way then this post will help you definitely.

Array in PHP

1.It is a collection of data of same or different data type.
2.It is used to store group of data simultaneously.
3.It can hold many values under a single name, and you can access the values by referring to an index number.
4.The indexing of array always start with 0.
5.array() function is used to create array in PHP.

Initialization of array method :

<?php
 $a=array(45,23,89,12,78);
?>

Printing of array element method 1:

 
<?php
//Array declaration
 $a=array(45,23,89,12,78);
 echo "Value at a[0]=".$a[0]."<br>";
 echo "Value at a[1]=".$a[1]."<br>";
 echo "Value at a[2]=".$a[2]."<br>";
 echo "Value at a[3]=".$a[3]."<br>";
 echo "Value at a[4]=".$a[4]."<br>";
/*
Value at a[0]=45
Value at a[1]=23
Value at a[2]=89
Value at a[3]=12
Value at a[4]=78
*/
?>

Printing of array element method using loop:

<?php
//Array declaration
 $a=array(45,23,89,12,78);
 for($i=0;$i<=4;$i++)
 {
 echo "Value at a[".$i."]=".$a[$i]."<br>";
 }
/*
Value at a[0]=45
Value at a[1]=23
Value at a[2]=89
Value at a[3]=12
Value at a[4]=78
*/

Types of Array in PHP

There are three types of Array in PHP
1.Indexed Array Click here to learn.
2.Associative Array Click here to learn.
3.Multi Dimension Array Click here to learn.

Request:-If you found this post helpful then let me know by your comment and share it with your friend. 

If you want to ask a question or want to suggest then type your question or suggestion in comment box so that we could do something new for you all. 

If you have not subscribed my website then please subscribe my website. Try to learn something new and teach something new to other. 

Thanks

Post a Comment

0 Comments