php tutorial - PHP Indexed Arrays - php programming - learn php - php code - php script



  • In php the indexed arrays starts with the numeric values that is ‘keys’, which are indexed in which the index value starts with zero (0).
  • The index values will be assigned automatically or you can assign manually also.

php developer Syntax :

array(
key[0]  => value0,
key[1] => value1,
key[2] => value2,
...
)
click below button to copy the code. php tutorial - team

php 7 Sample Code : sample php program

<!DOCTYPE html>
<html>
    <head>
        <title>Foreach-Loop</title>
    </head>
    <body>
        <?php
            $sample = array('zero','one','two');
            echo "First index value -  $sample[0]";
            echo "<br>";
            echo "Second index value -  $sample[1]";
            echo "<br>";
            echo "Third index value -  $sample[2]";
        ?>
    </body>
</html>
click below button to copy the code. php tutorial - team

php program Code Explanation :

Code Explanation for indexed arrays In PHP

  1. In this statement we define the indexed array for the variable “$sample” by using array function and the value are separated by using commas (,).
  2. In this echo statement we print the content “first index value and “$sample [0]” variable value. In the same way remaining two echo statements will be printed.

php coding Sample Output :

output for indexed arrays In PHP

  1. For the array “sample” the index value “0” prints the echo statement "First index value -Zero”.
  2. for the array “sample” the index value “1” prints the echo statement "Second index value -One”.
  3. For the array “sample” the index value “2” prints the echo statement "Third index value -two”.


Related Searches to php indexed arrays