PHP Numeric Array

PHP Numeric Array is an array in which numbers, strings, and any other object can be stored, but their indexes will be represented by numbers. Each element of the array is represented by an index number that begins with 0.

PHP Numeric Array Definition

There are two ways of defining PHP numeric array:





The example below shows how to create and access numeric arrays.

<h2> Example of Numeric Array</h2>
echo "Colour:  $colour[0], $colour[1] and $colour[2]";  

Count Length PHP Numeric Array

The count() method in PHP returns the length of an array.

<h2>Count Length of Numeric Array</h2>
echo "Colour:  $colour[0], $colour[1], $colour[2] and $colour[3] </br> </br>" ;  
echo "Total array elements are: ".count($colour);

Traversing PHP Numeric Array

In PHP array can be traversed easily by using foreach loop. Let’s look at a simple example of traversing the entire PHP array.

<h2> Traversing Numeric Array</h2>
foreach( $colour as $c )  
  echo "Colour is: $c<br />";