<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tiposaurus &#187; PHP</title>
	<atom:link href="http://tiposaurus.co.uk/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://tiposaurus.co.uk</link>
	<description>Rawrr.</description>
	<lastBuildDate>Wed, 10 Jun 2009 20:38:53 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How To: PHP &#8211; Roots in PHP (Square Root, Cube Root and nth Root)</title>
		<link>http://tiposaurus.co.uk/2009/06/how-to-php-roots-in-php-square-root-cube-root-and-nth-root/</link>
		<comments>http://tiposaurus.co.uk/2009/06/how-to-php-roots-in-php-square-root-cube-root-and-nth-root/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 20:38:03 +0000</pubDate>
		<dc:creator>Tiposaurus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[cube root]]></category>
		<category><![CDATA[nth root]]></category>
		<category><![CDATA[power]]></category>
		<category><![CDATA[roots]]></category>
		<category><![CDATA[square root]]></category>

		<guid isPermaLink="false">http://tiposaurus.co.uk/2009/06/how-to-php-roots-in-php-square-root-cube-root-and-nth-root/</guid>
		<description><![CDATA[To find the nth root of a number in PHP, we can use the pow(base, power) function, for example the cube root of 27 is equal to 27 raised to the power of 1/3, , since .  In general the nth root of x, .
To calculate the square root of a number, we can also [...]]]></description>
			<content:encoded><![CDATA[<p>To find the nth root of a number in PHP, we can use the <code>pow(base, power)</code> function, for example the cube root of 27 is equal to 27 raised to the power of 1/3, <img src="http://tiposaurus.co.uk/wp-content/cache/tex_e4b15074e4e5cd63faf08437958927da.png" align="absmiddle" class="tex" alt="\sqrt[3]{27} = 27^{1/3}" />, since <img src="http://tiposaurus.co.uk/wp-content/cache/tex_984cdc4ccfd45d5aa7b3bc0f224c9eec.png" align="absmiddle" class="tex" alt="3^3 = 27" />.  In general the nth root of x, <img src="http://tiposaurus.co.uk/wp-content/cache/tex_36016ebb1b1de6eb75941fc7286122a8.png" align="absmiddle" class="tex" alt="\sqrt[n]{x} = x^{1/n}" />.</p>
<p>To calculate the square root of a number, we can also use the <code>sqrt(number)</code> function.</p>
<h3>Example</h3>
<p>Some example code showing how to calculate roots in PHP is below:</p>
<pre>&lt;?php
// Square root
echo sqrt(49) . "&lt;br /&gt;";  // square root of 49
echo pow(49,1/2) . "&lt;br /&gt;"; // alternative to square root of 49
echo pow(8,1/2). "&lt;br /&gt;"; // square root of 8

// cube root
echo pow(8,1/3). "&lt;br /&gt;"; // cube root of 8
echo pow(27,1/3). "&lt;br /&gt;"; // cube root of 27

// higher roots
echo pow(390625,1/4). "&lt;br /&gt;";
echo "25^4 = " . pow(25,4) . "&lt;br /&gt;";

echo pow(1234, 1/6). "&lt;br /&gt;";
?&gt;</pre>
<p>The output from this example is as follows:</p>
<pre>7
7
2.8284271247462
2
3
25
25^4 = 390625
3.2750594908837</pre>
]]></content:encoded>
			<wfw:commentRss>http://tiposaurus.co.uk/2009/06/how-to-php-roots-in-php-square-root-cube-root-and-nth-root/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>HowTo: PHP &#8211; Raise a Number to the Power of Another (exponent in PHP)</title>
		<link>http://tiposaurus.co.uk/2009/06/howto-php-raise-a-number-to-the-power-of-another-exponent-in-php/</link>
		<comments>http://tiposaurus.co.uk/2009/06/howto-php-raise-a-number-to-the-power-of-another-exponent-in-php/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 20:37:19 +0000</pubDate>
		<dc:creator>Tiposaurus</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[exponent]]></category>
		<category><![CDATA[maths]]></category>
		<category><![CDATA[power of]]></category>
		<category><![CDATA[raise power]]></category>

		<guid isPermaLink="false">http://tiposaurus.co.uk/?p=6</guid>
		<description><![CDATA[You might need to raise a number to the power of another in a PHP script, for example  (sometimes written 3^5), or in general . This may also be used with negative powers where .  Of course, you&#8217;d probably want to do this for more complicated examples!
PHP has a function built in to do [...]]]></description>
			<content:encoded><![CDATA[<p>You might need to raise a number to the power of another in a PHP script, for example <img src="http://tiposaurus.co.uk/wp-content/cache/tex_b0072d9bc146289d3b03b3f0feeaa8c3.png" align="absmiddle" class="tex" alt="3^5 = 3 \times 3 \times 3 \times 3 \times 3" /> (sometimes written 3^5), or in general <img src="http://tiposaurus.co.uk/wp-content/cache/tex_b41952e9dfed8e1ed562fddafeca7c70.png" align="absmiddle" class="tex" alt="x^n" />. This may also be used with negative powers where <img src="http://tiposaurus.co.uk/wp-content/cache/tex_365fa071480f16c8bf56fa949858eaa3.png" align="absmiddle" class="tex" alt="x^{-n} = \frac{1}{x^n}" />.  Of course, you&#8217;d probably want to do this for more complicated examples!</p>
<p>PHP has a function built in to do this: <img src="http://tiposaurus.co.uk/wp-content/cache/tex_f373ea1e150dfbf415115e736ceb54a0.png" align="absmiddle" class="tex" alt="x^n = " /> <code>pow(x,n)</code>.</p>
<h3>Examples of &#8216;Power Of&#8217;</h3>
<p>Here are some examples, which raise a number to the power of another and display the output.  In the examples, &lt;br /&gt; inserts a line break to display the results neatly.</p>
<pre>&lt;?php
echo "3^5 = " . pow(3,5) . "&lt;br /&gt;"; // 243
echo "2^9 = " . pow(2,9) . "&lt;br /&gt;"; // 512
// Anything raised to the power of 0 is 1:
echo "99^0 = " . pow(99,0) . "&lt;br /&gt;"; // 1
// Negative powers:
echo "3^-1 = 1/3 = " . pow(3,-1) . "&lt;br /&gt;"; // 1/3 = 0.3333
echo "3^-2 = 1/(3^2) = " . pow(3,-2) . "&lt;br /&gt;"; // 1/9 = 0.1111
echo "&lt;br /&gt;";

// Loop through 2 raised to the 0,1,2,...,10:
for($i=0;$i&lt;=10;$i++)
{
  echo "2^" . $i . " = " . pow(2,$i) . "&lt;br /&gt;";
}
?&gt;</pre>
<p>Output of the example:</p>
<pre>3^5 = 243
2^9 = 512
99^0 = 1
3^-1 = 1/3 = 0.33333333333333
3^-2 = 1/(3^2) = 0.11111111111111

2^0 = 1
2^1 = 2
2^2 = 4
2^3 = 8
2^4 = 16
2^5 = 32
2^6 = 64
2^7 = 128
2^8 = 256
2^9 = 512
2^10 = 1024</pre>
<p>Good luck! If you have any questions about this article then please post a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://tiposaurus.co.uk/2009/06/howto-php-raise-a-number-to-the-power-of-another-exponent-in-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
