Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.