PHP Numeric Array
An array that stores values in numeric integer index system is called numeric array. In PHP programming language, numeric array accepts set of values and stores each accepted value in a numeric based place in it. The allocated place for every value in array is called key. Each key is named by numeric integer index system. In other words, the name of key in numeric array is 0, 1, 2, 3, 4, 5, ...... It can store characters, words, group of words, strings, variables, numbers and any data as values by assigning a number to each value.
The numeric array is simulated as displayed in above graphic designing art work. Consider, there are n+1 values and each value is denoted by a ball in this graphical representation. Each value is located in a place which is known key. Each key place is denoted by numeric integer system numbers. Every key place is represented by a box in our graphic designing art work. As you know, we have assumed n+1 values so, numeric array has to place them in n key places. In this way, the concept of numeric array is defined in php and our graphic design art work helps you to understand numeric array easily.
The syntax of numeric array is defined in PHP programming language as given in below code box.
- Type array word inside the PHP start and end tags.
- Type Parenthesis ( ) start and close brackets.
- Inside the open and close parenthesis, each value is placed inside either single or double quotes but each value must be separated by a comma.
- After parenthesis close bracket, give a semi colon to end the syntax properly.
In this way, the values in numeric array are placed in syntax.
As assumed in theory of numeric array simulator, consider n+1 values and each value is placed inside the array in quotes but comma separation. Also assume the entire numeric array is equal to $nar in order to use the entire array by $nar everywhere in PHP program.
<?php $nar = array("value1","value2","value3","value4","value5",............,"valuen+1"); print_r($nar); ?>
The print_r() function returns list of stored values in array keys in web browser as demonstrated below.
Array (  => value1  => value2  => value3  => value4  => value5  => value6 ............. ............. ............. [n] => valuen+1 )
According to above browser preview, the structure of the numeric array is displayed. The first value is placed at 0, the second value is placed at 1, and this process is continued up to last value which means the n+1 value is placed at n in array.
For example, consider five values and placed them in a numeric array and output it.
<body> <?php $spiderman = array("Peter Parker","Ben Parker","Aunt May","Harry","Mary Jane Watson"); echo "<strong>List of Some Main Characters in Spiderman Cartoon Series</strong>"; print_r($spiderman); ?> </body>
The print_r() function outputs the entire array in web browser as per its integer keys.
Array (  => Peter Parker  => Ben Parker  => Aunt May  => Harry  => Mary Jane Watson )
As you are seeing here that the first value is placed in zero key; second, third, fourth and fifth values are placed at 1, 2, 3 and 4 positions respectively in numeric array. In this way, numeric array works in php programming language.