<?xml version="1.0" encoding="utf-8" ?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
<channel>
<title>Calculating the median &amp; average values of an array with PHP</title>
<link>http://www.mdj.us/</link>
<description>Calculate the average and median values of an array of numbers with PHP.</description>
<language>en</language>
<item>
<title>Matt</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1638</link>
<pubDate>Tue, 13 Mar 2012 13:27:09 +0000</pubDate>
<content:encoded><![CDATA[Hi An,<br />
<br />
Wouldn't using asort in the above function do what you're asking?<br />
<br />
<a href="http://www.php.net/manual/en/function.asort.php" rel="nofollow">http://www.php.net/manual/en/function.asort.php</a>]]></content:encoded>
</item>
<item>
<title>An</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1637</link>
<pubDate>Sun, 11 Mar 2012 18:23:55 +0000</pubDate>
<content:encoded><![CDATA[Hi what about: write a function to find the avarage value of array W from low index to high index ? Thanks]]></content:encoded>
</item>
<item>
<title>mary</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1503</link>
<pubDate>Tue, 18 Oct 2011 09:41:55 +0000</pubDate>
<content:encoded><![CDATA[so helpful. thank you so much.]]></content:encoded>
</item>
<item>
<title>nathan</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1234</link>
<pubDate>Thu, 19 Aug 2010 01:11:36 +0000</pubDate>
<content:encoded><![CDATA[to simplify the function further, you could write<br />
<br />
function calculate_average($arr) <br />
{<br />
    return array_sum($arr)/count($arr)<br />
}]]></content:encoded>
</item>
<item>
<title>Matt</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1218</link>
<pubDate>Sat, 31 Jul 2010 04:41:15 +0000</pubDate>
<content:encoded><![CDATA[Ah, true true Justin, if they aren't correctly sorted going in, that is a must. I will amend the function. Thanks.]]></content:encoded>
</item>
<item>
<title>Justin Noel</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1217</link>
<pubDate>Fri, 30 Jul 2010 18:50:54 +0000</pubDate>
<content:encoded><![CDATA[There is one bug in the MEDIAN calculation.  You must sort the array of values first.  If you fail to do this, you will get all kinds of incorrect results.<br />
<br />
...<br />
sort($arr);<br />
$count = count($arr); //total numbers in array<br />
...]]></content:encoded>
</item>
<item>
<title>Matt</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1191</link>
<pubDate>Thu, 24 Jun 2010 22:42:32 +0000</pubDate>
<content:encoded><![CDATA[Hi Kris, thanks for the comment, that is true the way the function is written currently.<br />
<br />
The primary reason I used a loop was so you can mess around with each array element; i.e. check with is_numeric or something along those lines.]]></content:encoded>
</item>
<item>
<title>Kris</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1190</link>
<pubDate>Thu, 24 Jun 2010 22:31:11 +0000</pubDate>
<content:encoded><![CDATA[Nice functions.<br />
<br />
In the calculate_average function, you can replace the foreach loop with this:<br />
<br />
$total = array_sum($arr);<br />
<br />
Thanks!]]></content:encoded>
</item>
<item>
<title>Matt</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1027</link>
<pubDate>Fri, 26 Mar 2010 11:18:43 +0000</pubDate>
<content:encoded><![CDATA[I'm not sure Rod. <br />
<br />
They've got min: <a href="http://www.php.net/manual/en/function.min.php" rel="nofollow">http://www.php.net/manual/en/function.min.php</a><br />
and max: <a href="http://www.php.net/manual/en/function.max.php" rel="nofollow">http://www.php.net/manual/en/function.max.php</a> <br />
<br />
but no avg... go figure.]]></content:encoded>
</item>
<item>
<title>Rod</title>
<description></description>
<link>http://www.mdj.us/web-development/php-programming/calculating-the-median-average-values-of-an-array-with-php/#comment-1026</link>
<pubDate>Fri, 26 Mar 2010 05:31:54 +0000</pubDate>
<content:encoded><![CDATA[Thanks, that helped.<br />
<br />
How come php don't have a native avg function while js does?]]></content:encoded>
</item>
</channel>
</rss>

