Associative Arrays in PHP

Associative Arrays in PHP
Rating: 5 - 2 Votes

Associative Arrays in PHP

phpAssociative arrays are object-indexed collection of items.  They are also known as key-value pairs where index act as key and its item act as value.   A simple array is used when you want to create collection of items and you want to store them in a certain order.  An associative array is used when you want to store items based on their key or a label.  This can be better understood with an example where you have a bunch of boxes with a label on them like shoe, dress, socks etc.  Each box contains items depending upon its label which will make easy for everyone to pick an item from right box.  Like simple array, you can also add more items to an associative array.  Example is given below.