note 96133 rejected from function.stats-stat-percentile by danbrown
| From: | danbrown@php.net | Date: | Wed, 10 Feb 2010 15:07:43 +0000 |
| Subject: | note 96133 rejected from function.stats-stat-percentile by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-165832@lists.php.net to get a copy of this message | ||
Note Submitter: jgrant at chks dot co dot uk
----
Has anyone come across a 'feature' of the function where by an array passed in is
automatically sorted, and you lose any keys defined within the array? This happens if the array is a
copy or the array is passed in via another function.
If $tmpArray contains the following information:
Array
(
[51] => 150
[52] => 178
[53] => 116
[54] => 109
[61] => 45
[62] => 29
[63] => 26
[64] => 42
[71] => 32
[72] => 100
[73] => 120
[74] => 122
[81] => 54
[82] => 64
[83] => 51
[84] => 42
[91] => 46
[92] => 67
)
And you run the code below:
list($percent05, $percent95) = percentiles($tmpArray);
print "<pre>"; print_r($tmpArray); print "</pre>";
function percentiles($newArray)
{
$percent05 = stats_stat_percentile($newArray, 0.05);
$percent95 = stats_stat_percentile($newArray, 0.95);
return(array($percent05, $percent95));
}
The outputted array is now:
Array
(
[0] => 26
[1] => 29
[2] => 32
[3] => 42
[4] => 42
[5] => 45
[6] => 46
[7] => 51
[8] => 54
[9] => 64
[10] => 67
[11] => 100
[12] => 109
[13] => 116
[14] => 120
[15] => 122
[16] => 150
[17] => 178
)