Some types of plants grow better when planted near a plant of another species. This is called companion planting. It is an older system of planting vegetables, herbs, and other plants, that was used before herbicides and fertilizers were common, but still works.
In some cases, companion planting traps pests in a bait crop to save the food crop. For example, planting marigolds near tomatoes helps trap root rot nematodes in the marigolds, sparing the tomatoes. Marigolds also repel tomato hornworms from tomatoes.
Another use for companion planting is to encourage pollinators such as bees and hummingbirds to visit your garden. Planting flowers that bees and hummingbirds are attracted to will draw them in. They will stay and pollinate your squash and cucumbers and other plants that need their help to grow. Planting herbs and flowers among your vegetables is the easiest way to accomplish this particular type of companion planting.
Part of companion planting is understanding that some plants should not be planted near each other. Dill and fennel do not get along, and cucumbers and cantaloupe will cross pollinate and produce foul tasting fruit. These plants should be separated as much as possible in the garden.
One of the most famous cases of companion planting is the Three Sisters method of planting corn, beans, and squash used by Native Americans. The corn is planted first and allowed to germinate and come up. Then the beans are planted and they use the corn as poles to hold themselves up. In return, they fix nitrogen for the corn to use to grow. Finally, the squash is planted between the rows of beans and corn. The squash is shaded so it does not get too hot and sunburn the squash, while providing a ground cover that keeps down weeds near the beans and corn.
This is also an example of spatial intercropping, in that the shade tolerant squash are planted under the corn and beans. The spiny squash vines are also said to repel raccoons from looting the sweet corn in the field.
Companion plants can also be planted to provide nurseries and habitat for beneficial insects, which then hunt down pests on the nearby crops. Again, planting herbs and flowers around your vegetables is the easiest way to accomplish this goal.
While scientists are only now seriously beginning to explore companion planting, it has been practiced for thousands of years. It is mentioned by Theophrastus (300 B.C.E.), Pliny (50 C.E.), and John Gerard (1597 C.E.). In China the mosquito fern has been planted around rice to fix nitrogen and shade out weeds for thousands of years. Something does not usually endure that long unless it works to some degree.
Companion planting was widely promoted in the 1970s by organic producers as a way to protect plants while reducing the need for herbicides and fertilizer. There is a famous book on companion planting by Louise Riotte called Carrots Love Tomatoes that mentions many more ways to practice companion planting in your garden if you are interested in reading further on this topic.