|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-01-06 17:25 UTC] tyrael@php.net
-Package: PECL bug system
+Package: stats
[2016-01-20 23:17 UTC] y dot uchiyama dot 1015 at gmail dot com
[2016-05-28 00:22 UTC] uchiyama@php.net
-Status: Open
+Status: Assigned
-Assigned To:
+Assigned To: uchiyama
[2016-05-28 05:22 UTC] uchiyama@php.net
-Status: Assigned
+Status: Closed
[2016-05-28 05:22 UTC] uchiyama@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Oct 27 16:00:01 2025 UTC |
Description: ------------ When using the "stats_stat_percentile" function, the array passed in is being modified, regardless of how you pass it in. For example: $tmpArray contains: 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 ) When used with the code to reproduce below, is being modified to the array below: 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 ) Since I am not passing in the array to my function by reference, I would expect a 'copy' of my array to be used, leaving my original array intact. Reproduce code: --------------- $tmpArray = 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); 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)); } Expected result: ---------------- 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 ) Actual result: -------------- 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 )