Home Internet PHP Lessons- Create An Array In PHP Programming

PHP Lessons- Create An Array In PHP Programming


PHP Array

An Array is a variable that can hold more than one value . To create an array in PHP syntax is almost same as variable syntax . Read more what is an array .


$var = array("value","value","value" );

In the upper php code array name is start from $ sign and variable name  “$variable_name” .  Then value is array() function . Array ( ) is built in function in php and you have no need to create this function .

Just call the array ( ) function and write array values in the braces . For example array (“value1″,”value2″,”value3” ) . These values are numerically indexed . Indexed means value1-index number is 0 , value2 -index number is 1 , as so on .

It means if you call index number 0 , that means you call value1 .

Array Example:

$fruits = array("banana","apple","pineapple");
echo "Fruit name is ".$fruits[1];

Copy this code in any php editor like notepad++ or simple notepad. Save it as index.php . When you run this code ,result is

Fruit name is apple

In this php code $fruits is array name .Which can hold multiple values and indexed it . And fruits banana, apple and pineapple are values of array . When you call $fruits[1] , it means you call second value of array. When you change $fruits[2] , then result is “Fruit name is pineapple” .

READ ALSO : -  Solution- Onclick Function Not Working Wordpress Post

An array can hold same type of values .

See video help