PHP Arrays


Usage of Arrays in PHP

Basically arrays are used to store the multiple values into the single variable. The values store by the index number.

How to fetch the arrays values ?

The answer is the simple , we can access the array values by the value index number. We can initialized (assigning the values) the array also by the index number. The index of any array starts from Zero [0] .

PHP program to store the values into the array

Store at least five different vehicles manufacturer companies into an array .

<?php $vehicles = array('Corolla','Mercedes','Cersedia','Honda','Ford'); ?>

PHP program to fetch the values from an array

The values in an array can access by the index or sequence .

Syntax: $variable_name[' index number here '] ;

<?php $vehicles = array(' Corolla ',' Mercedes ',' Cersedia ',' Honda ',' Ford '); echo "Five Vehicles Manufacturer Companies are :".$vehicles[0].$vehicles[1]. $vehicles[2].$vehicles[3].$vehicles[4]; ?> Output: Five Vehicles Manufacturer Companies are : Corolla Mercedes Cersedia Honda Ford

In the next chapter we will discuss the FOR LOOP and will insert and fetch the array's data using FOR LOOP .

Chapter Next »