tenpastmidnight blog

Making hay while the sun shines

'To the power of' in PHP

If you're programming in PHP and want to do a 'to the power of', you might think you could just use the caret symbol (^) between two numbers, like this:

print 2^5;

But no, this will give you some gobbledegook like bWH�. You need to use the pow() function, like this:

print pow(2,5);

Which will give you 32, which is what you want.

I haven't got time to dig in to why PHP ignored this sort of mathematical notation, when it'll treat + * - and / properly, but it's rather annoying.

Labels: , ,

This page is powered by Blogger. Isn't yours?