title: how mapping works in solidity, and is mapping analogous to another concept in other popular languages
body: <p>Can anyone explain how <code>mapping</code> works and why exactly it is used? Like an array is a collection of items. I have no experience in solidity, I'm just starting. I found this code on the solidity official documentation page. </p>
  
  <pre><code>pragma solidity ^0.4.11;
  
  Contract CrowdFunding {
  // Defines a new type with two fields.
  struct Funder {
      address addr;
      uint amount;
  }
  
  struct Campaign {
      address beneficiary;
      uint fundingGoal;
      uint numFunders;
      uint amount;
      mapping (uint =&gt; Funder) funders;
  }
  
  uint numCampaigns;
  mapping (uint =&gt; Campaign) campaigns;
  
  function newCampaign(address beneficiary, uint goal) returns (uint campaignID) {
      campaignID = numCampaigns++; // campaignID is return variable
      // Creates new struct and saves in storage. We leave out the mapping type.
      campaigns[campaignID] = Campaign(beneficiary, goal, 0, 0);
  }
  
  function contribute(uint campaignID) payable {
      Campaign storage c = campaigns[campaignID];
      // Creates a new temporary memory struct, initialised with the given values
      // and copies it over to storage.
      // Note that you can also use Funder(msg.sender, msg.value) to initialise.
      c.funders[c.numFunders++] = Funder({addr: msg.sender, amount: msg.value});
      c.amount += msg.value;
  }
  
  function checkGoalReached(uint campaignID) returns (bool reached) {
      Campaign storage c = campaigns[campaignID];
      if (c.amount &lt; c.fundingGoal)
          return false;
      uint amount = c.amount;
      c.amount = 0;
      c.beneficiary.transfer(amount);
      return true;
  }
  }
  </code></pre>