What is the difference between associative array and indexed array?
Associative Arrays | Indexed or Numeric Arrays |
---|---|
This is a type of arrays which used named specific keys to assign and store values in the database. | This type of arrays store and assign values in a numeric fashion with count starting from zero. |
BY Best Interview Question ON 07 Apr 2020
Example
Example of an associative array:
$name_two["i am"] = "zara";
$name_two["anthony is"] = "Hello";
$name_two["ram is"] = "Ananya";
echo "Accessing elements directly:\n";
echo $name_two["i am"], "\n";
echo $name_two["anthony is"], "\n";
echo $name_one["Ram is"], "\n";
Output:
Accessing elements directly:
zara
Hello
Ananya
Example of an indexed or numeric array:
$name_two[1] = "Sonu Singh";
echo "Accessing the array elements directly:\n";
echo $name_two[1], "\n";
Output:
Sonu Singh