PHP Core / Array / Associative Array
Array
-
STEP
Array variables allow us to group related PHP data values together in a list using a single variable name. We can store multiple data in a single variable. 1. Define variable or variable assignment
Let us define separate variable for storing data of students , teachers and staff
The above method is not good for managing or maintaining the variables while developing an application
2. Group the related data and store in a single variable using array
Syntax
$variable_name = []; OR $variable_name = ['key' => 'value']; 1. $ sign must be in front of the variable name
2. = sign for assigning the value to a variable
3. => sign for separating key and value in an array
4. , sign for separating the multiple values in an array"manoj", "age" => 20, "dob" => "20-01-2020", "english" => 50, "malayalam" => 60, "computer" => 70, "maths" => 80, "gk" => 90]; // OR $student["name"]="manoj"; $student["age"]=20; $teacher=["name" => "manoj", "age" => 20, "dob" => "20-01-2020", "basic" => 25000, "hra" => 5000, "ta" => 100]; // OR $teacher["name"]="manoj"; $teacher["age"]=20; $staff=["name" => "manoj", "age" => 20, "dob" => "20-01-2020", "basic" => 25000, "hra" => 5000, "ta" => 100]; // OR $staff["name"]="manoj"; $staff["age"]=20; ?> 3. Read the array data with key
4. update array data with key
5. output to the browser using echo
6. Show the data user friendly
Student Name Student Age Student DOB Teacher Name Teacher Age Teacher DOB Staff Name Staff Age Staff DOB