tenpastmidnight blog
Making hay while the sun shines
» Monday, April 21, 2008 «
'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.
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: development, php, programming