In this tutorial we will learn about Arrays in PHP. In simple words an Array is variable which makes us able to store more than one same kind values using a single variable name. For example you want to save name of hundred students in variables. It mean you have to make 100 variables. But it make your code so complicated and It is also time wasting. Instead of spending so much time on making variables you can store all 100 names of students in single variable using an array. In this tutorial we will learn basics of array like how to define an Array and how to Initialize an Array etc.
In an Array values store using single variable name. But we use index number to add or fetch value from Array. For example you want to store name of hundred students in student Array. Then you have to add values like name of first student on the 0 index of student array, and name of next student on 1st index like this.
Defining and Initializing an Array: Defining an Array in PHP is so simple. The simplest way to define an array using array() function. Check the example below to understand it clearly.
80, "Sameer"=>90, "Mohan"=>85); $marks["Ali"]=80; $marks["Sameer"]=90; $marks["Mohan"]=85; print_r($stumarks); print_r($marks); ?>
"ali", "marks" => 80, ), array( "name" => "Sameer", "marks" => 90, ), array( "name" => "Mohan", "marks" => 85, ) ); print_r($studentInfo); ?>