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.
<?php $a=array(45,23,89,12,78); ?>
<?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 */ ?>
<?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 */
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.
0 Comments