Breaking News

Index Array in php




Array in php:

Array is a special variable which can store/hold multiple values in one single variable.
Size and data type is not important in PHP while defining array.

To define array in php:
$variable_name = array( );

Types of array:
1) Index Array
2) Associative array

Index array:
Arrays with a numeric index is called index array. It’s default index is 0.

To store and display number from 1 to 10 using index array:

<?php
$arr = array( );
$arr[0] = 1;
$arr[1] = 2;
$arr[2] = 3;
$arr[3] = 4;
$arr[4] = 5;
$arr[5] = 6;
$arr[6] = 7;
$arr[7] = 8;
$arr[8] = 9;
$arr[9] = 10;
echo $arr[0]. “<br>”;
echo $arr[1]. “<br>”;
echo $arr[2]. “<br>”;
echo $arr[3]. “<br>”;
echo $arr[4]. “<br>”;
echo $arr[5]. “<br>”;
echo $arr[6]. “<br>”;
echo $arr[7]. “<br>”;
echo $arr[8]. “<br>”;
echo $arr[9]. “<br>”;

?>
Or
<?php
$arr = array(1,2,3,4,5,6,7,8,9,10); 

echo $arr[0]. “<br>”;
echo $arr[1]. “<br>”;
echo $arr[2]. “<br>”;
echo $arr[3]. “<br>”;
echo $arr[4]. “<br>”;
echo $arr[5]. “<br>”;
echo $arr[6]. “<br>”;
echo $arr[7]. “<br>”;
echo $arr[8]. “<br>”;
echo $arr[9]. “<br>”; 

?>

Out put:
1
2
3
4
5
6
7
8
9
10

No comments