Jump to content

frequency chart


resago

Recommended Posts

just an example:

 

I had a 6 meg text file with the following data:

 

Proc Code  ICD9 Code  - each are alpha numeric

 

here's the fun part, there can be multiple proc codes of the same value, but a gamut of icd9 codes.

 

here is an example of using php's flexibility of array indexing.

 

$codes = array("cpt"=>array(),"icd9"=>array());

$handle = @fopen("codes.txt", "r");

if ($handle) {

    while (!feof($handle)) {

        $buffer = rtrim(fgets($handle));

        $token = preg_split('/ +/', $buffer);

        $procs[]= $token[0];

        $codes["cpt"][$token[0]]["icd9"][$token[1]]++;

    }

    fclose($handle);

}

$procs=array_unique($procs);

sort($procs);

 

because php allows you to used undefined array offsets, this works beautifully.

 

then I just run through the array and get all my values and counts.

 

 

foreach ($procs as $cpt){

  $sum = array_sum($codes["cpt"][$cpt]["icd9"]);

  $icd9s = array_keys($codes["cpt"][$cpt]["icd9"]);

  $i=0;

  foreach ($codes["cpt"][$cpt]["icd9"] as $icd9){

    $avg = $icd9 / $sum;

    $table[] = "$cpt,$icd9s[$i],$icd9,$avg\n";

    $i++;

  }

}

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/86852-frequency-chart/
Share on other sites

I think using $array[] is just a shortcut for $array[count($array)]. A lot of languages have variable-length array support. Nice example though.

 

$array[] = $something;

 

is a shortcut for

 

array_push($array, $something);

 

IE. add $something as the next element in $array

 

EDIT: Yes, I guess that amounts to $array[count($array)] = $something;

Link to comment
https://forums.phpfreaks.com/topic/86852-frequency-chart/#findComment-443917
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.