PHP Numeric Arrays - Code

PHP ARRAYS Previous Next PHP Associative Arrays


A numeric array stores each array element with a numeric index.

There are two methods to create a numeric arrays.

1. In the first method the indexes are automatically assigned(the index starts at 0).

$names = array("John Doe","Larry Page"," Mark Zuck","Satya","Sundar");

2. In the second method the indexes are assigned manually.

$names[0]="John Doe";

$names[1]="Larry Page";

$names[2]="Mark Zuck";

$names[3]="Satya";

$names[4]="Sundar";

Filename: php / numeric-array1.php


Code
<?php  
// numerica array 1
$names = array("John Doe","Larry Page","Mark Zuck","Satya","Sundar");

foreach($names as $name){
echo $name." 
"; } ?>

Running Step.


Type Url - https://localhost/php/numeric-array1.php

Filename: php / numeric-array2.php


Code
<?php 
// numerica array 2

$names[0]="John Doe";
$names[1]="Larry Page";
$names[2]="Mark Zuck";
$names[3]="Satya";
$names[4]="Sundar";

echo "Hi ".$names[0]." and ".$names[1].", How are you ?";
?>

Running Step.


Type Url - https://localhost/php/numeric-array2.php


Tags: PHP Numeric Arrays php Code Programming Language


Was this helpful ?

Related Code