May 2017
Intermediate to advanced
340 pages
8h 16m
English
An associative array is accessed by a key which can be any string. In an associative array, values are stored against the key instead of a linear index. We can use an associative array to store any type of data, just like the numeric array. Let us create a student array where we will store student information:
$studentInfo = []; $studentInfo['Name'] = "Adiyan"; $studentInfo['Age'] = 11; $studentInfo['Class'] = 6; $studentInfo['RollNumber'] = 71; $studentInfo['Contact'] = "info@adiyan.com"; foreach($studentInfo as $key => $value) { echo $key.": ".$value."\n"; }
Here is the output of the code:
Name: Adiyan Age: 11 Class: 6 RollNumber: 71 Contact: info@adiyan.com
Here we are using each key to hold one piece of data. We can ...
Read now
Unlock full access