Brushing your teeth works best when your brush is in tip-top condition. Lying the brush down hinders the drying process which can allow more bacteria to grow between sessions. Putting it into a cup is a cheap and cheerful alternative but cups can quickly get gunky at the bottom, and it is not suitable for powered or bamboo toothbrushes which should not sit in puddles of water.
The best all-round solution for keeping your brush safe is to buy a rack. This holds the shaft, allowing the head to dry and keeping the handle dry. Some models come with integrated head covers, which keep the head clean from splashes from other bathroom users. Racks are widely available in bathroom and houseware stores .