The purpose of dihedral is to confer stability in the roll axis. A popular but erroneous explanation for how it works is that if the aircraft is perturbed such that one wing is lowered relative to the other, dihedral causes the lower wing to increase its surface area relative to the airflow, thus increasing its lift. This acts to oppose the original roll motion. A perhaps better way to think about this is to see that the aircraft is sitting in the bottom of a shallow V-shaped "slot" in the air, thanks to the angle of the wings. This position is naturally stable. The true explanation for the action of dihedral is this: If a disturbance causes an aircraft to roll away from its normal position, the aircraft will sideslip in the direction of the down-going wing. This creates an airflow component along the length of the wing from tip to root. The dihedral angle can be seen as presenting a positive angle of attack to this lateral flow, hence generating some additional lift. It is this lift which restores the aircraft to its normal attitude. The apparent increase in surface area is in fact an illusion and contributes no additional lift.
Most aircraft in the civilian or transport sector use dihedral for stability. Military combat aircraft, in contrast, often have flat wings or anhedral. This reduces inherent stability but increases manoeuvrability. Many military aircraft are in fact inherently unstable, and only fly due to the constant vigilance of on-board computers.
A side effect of dihedral can be roll-coupling, a tendency for an aircraft to "corkscrew" through the air under certain conditions. This rolling motion, called a dutch roll, is unpleasant to experience for those flying, and can lead to loss of control or can overstress an aircraft. A certain amount of anhedral can combat this effect. Pronounced anhedral is also often seen on aircraft with a high mounted wing, such as the BAe 146, Lockheed Galaxy and others. In such designs, the high mounted wing itself confers roll stability (due to the pendulum effect of the fuselage, engines, etc), so additional dihedral is not required. In fact such designs can be excessively stable, so the anhedral is added to cancel out some of the roll stability to ensure that the aircraft can be easily manoeuvred.