The traditional array definition method is as follows:
1 <? PHP 2 $names [0]= ' Chinese '; 3 $names [1]= ' math '; 4 $names [2]= ' 中文版 '; 5 6 Echo $names [2]; 7 ?>
What are the drawbacks? is not intuitive, because the reference array element is indexed, and the index is a number, you do not have a good understanding of what this number means, which is a bit like the relationship between IP address and domain name. In order to solve this problem, the concept of associative array is proposed.
What's the meaning of associative arrays? That is, when we define an array, we can give a name to the elements in the array, and you can use that name to refer to the array elements.
See two examples:
1 <? PHP 2 $books [' Lilei ']= 3; 3 $books [' hanmeimei '] = 5; 4 $books [' jim '] =n; 5 6 Echo $books [' Jim ']. ' <br> '; 7 8 ?>
1 <? PHP 2 3 $books=array(' Lilei ' =>3, ' Hanmeimei ' =>5, ' Jim ' =>12); 4 5 Echo $books [' Jim ']. ' <br> '; 6 7 ?>
Associative arrays are a bit like a hash table in a dictionary and data structure in Python.
PHP Learning notes-associative arrays