Advertisements
Advertisements
Question
Explain Indexed array and Associate array in PHP.
Answer in Brief
Advertisements
Solution
- Indexed Arrays:
Arrays with a numeric index for the available values in array variable which contains key-value pair as user/developer can take the values using keys.
Example:
<?php $teacher_name=array(“Iniyan”, “Kavin”, “Nilani”); echo “The students name are “ . $teacher_name[0]. “, “ . $$teacher_name[l]. “ and” . $teacher_name[2]. ?> -
Associative Arrays:
- Associative arrays are a key-value pair data structure.
- nstead of having storing data in a, linear array, with associative arrays you can store your data.
Example:
<?php $Marks=array(“Student1”=>“35”,“Student2”==>“17”,“Student3”=>“43”); echo “Student1 mark is” . $Marks[‘Student1’]. “ is eligible for qualification”; echo “Student2 mark is” . $Marks[‘Student2’]. “ is not eligible for qualification”; ?>
shaalaa.com
Is there an error in this question or solution?
