note 96133 added to function.stats-stat-percentile
| From: | jgrant at chks dot co dot uk | Date: | Wed, 10 Feb 2010 15:01:52 +0000 |
| Subject: | note 96133 added to function.stats-stat-percentile | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165831@lists.php.net to get a copy of this message | ||
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
)
----
Server IP: 78.110.173.36
Probable Submitter: 194.106.220.19
----
Manual Page -- http://www.php.net/manual/en/function.stats-stat-percentile.php
Edit -- https://master.php.net/note/edit/96133
Del: integrated -- https://master.php.net/note/delete/96133/integrated
Del: useless -- https://master.php.net/note/delete/96133/useless
Del: bad code -- https://master.php.net/note/delete/96133/bad+code
Del: spam -- https://master.php.net/note/delete/96133/spam
Del: non-english -- https://master.php.net/note/delete/96133/non-english
Del: in docs -- https://master.php.net/note/delete/96133/in+docs
Del: other reasons-- https://master.php.net/note/delete/96133
Reject -- https://master.php.net/note/reject/96133
Search -- https://master.php.net/manage/user-notes.php