Last active
August 29, 2015 14:25
-
-
Save tghilardi/e904814fcbe674433563 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// calculate nps score | |
// using formula promoters-detractors / number of respondents * 100 | |
/** | |
* @param array | |
* @return float | |
*/ | |
function output_real_nps($nps_array) | |
{ | |
$detractors=0; | |
$promoters=0; | |
$arr_length=count($nps_array); | |
for ($i=0;$i<$arr_length;$i++) | |
{ | |
if (is_numeric($nps_array[$i])) | |
{ | |
if ($nps_array[$i] <= 6 && $nps_array[$i] >= 0) | |
$detractors++; | |
if ($nps_array[$i] >= 9 && $nps_array[$i] <= 10) | |
$promoters++; | |
} | |
} | |
// div by 0 not allowed | |
if ($arr_length>0) | |
$nps_score=(($promoters-$detractors)/$arr_length)*100; | |
else | |
$nps_score='0'; | |
return round($nps_score,1); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment