Indexed Array in PHP | Syntax | Initialization | Examples

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

Indexed Array in PHP

1.It is a type of array in which each element of array is associated with index value.
2.It is also called Numeric array.
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 indexed array method ::

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

Printing of indexed 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 indexed 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