Saying that we have learned something “by heart” means, of course, that we have committed it to memory.
It more than likely involved a process of repetition, called learning by rote.
Rote is from rota, the Latin word for wheel, meaning that to memorize something we turn it over in our minds many times before knowing it by heart.
The ancient Greeks believed that it was the heart, and not the brain, where thoughts were held.
When we memorize something we say, “I know it by heart”.