What is the ideal age to get a PhD?
There is, frankly, no "ideal" age for starting a Ph.D. There's not even a "better" time. All that is really important is demonstrating that you have an aptitude for doing research in the proposed field of study. If you can demonstrate that at age 20, great; if you've had a change of heart at 30 or even 40, and decide you want to go back to school, that's cool, too.

However, there is an advantage in doing it sooner rather than later—adjusting back to "student" habits is easier when you're closer to finishing your undergraduate than when you're older. It's also usually easier to move around when you're younger than when you're older and might have a (larger) family to worry about.

But from the perspective of someone who reviews admissions applications, I'd say the single most important factor is demonstrating your potential to be a PhD level researcher. If you can do that, I'm not nearly as concerned about someone having a 3.4 versus a 3.6 or a 3.8 GPA, or a 155 or a 165 on the GRE.