PHP Array last element being lost from using another array as dictionary -


i have 3 arrays. 1 contains given title information user stored in $attributenames. second has data user stored in $anesdata. (so first 2 related) , third dictionary can out information want using index stored in $medicalinstancedictionary.

this first one:

array (     [0] => patient mrn     [1] => patient last name     [2] => patient first name     [3] => patient middle name     [4] => patient ssn     [5] => patient sex     [6] => invoice     [7] => transaction     [8] => date of procedure     [9] => posting date     [10] => location     [11] => charge amt     [12] => provider     [13] => fsc1     [14] => fsc2     [15] => patient dob     [16] => attending surgeon     [17] => attending surgeon     [18] => cpt codes     [19] => asa classfication     [20] => anesthesia crna     [21] => anesthesia resident     [22] => surgery start time     [23] => surgery end time     [24] => svc unit     [25] => facility name     [26] => billing number     [27] => billing area name     [28] => procedure modifier1     [29] => procedure modifier2     [30] => procedure modifier3     [31] => primary dx     [32] => secondary dx  ) 

the second array 2 dimensional array, each line equivalent 1 patient. first patient looks this(put in x's instead of actual patient data):

[0] => array     (         [0] => xxxx         [1] => xxxx         [2] => xxxx         [3] => xxxx         [4] => xxxxx         [5] => xxxx         [6] => xxxx         [7] => xxx         [8] => xxxxx         [9] => xxxx         [10] => xxxx         [11] => xxxxx         [12] => xxxx         [13] => xxxxx         [14] => xxxx         [15] => xxxx         [16] => xxxxxxx         [17] => xxxxx         [18] => xxxxx         [19] => xxxx         [20] =>          [21] => xxxxx         [22] => xxxxx         [23] => xxxxx         [24] => xxxxx         [25] => xxxx         [26] => xxxxx         [27] => xxxx         [28] => xxxxxxxx         [29] => xxxx         [30] =>          [31] => xxxxxxx         [32] => xxxxxxx      ) 

then dictionary looks this:

$medicalinstancedictionary = array(     'cpt codes' => "cpt_code",     'asa classfication' => "mg_asa_class",     'facility name' => "facility_name",     'billing number' => "billing_number",     'billing area name' => "billing_area_name",     'procedure modifier1' => "procedure_modifier1",     'procedure modifier2' => "procedure_modifier2",     'primary dx' => "primary_dx",     'secondary dx' => "secondary_dx",     'invoice' => "fin" ); 

i doing nested foreach loop each row.

foreach ($dataarray $dataindex => $datavalue) {     $out = "";     foreach ($dictionary $index => $value)     {         //find patient mrn in $attributearray , it's index         $attributeindex = array_search($index, $attributearray);         if ($attributeindex===false) {             echo "error : ".$index." not found <br />";         } else {              echo "<br>the attribute is: ".$value." index is: ".$attributeindex."<br>";         }  (more code....) } (more code....) } 

that echo statement looks this:

the attribute is: cpt_code index is: 18  attribute is: mg_asa_class index is: 19  attribute is: facility_name index is: 25  attribute is: billing_number index is: 26  attribute is: billing_area_name index is: 27  attribute is: procedure_modifier1 index is: 28  attribute is: procedure_modifier2 index is: 29  attribute is: primary_dx index is: 31 error : secondary dx not found  attribute is: fin index is: 6 

i have no idea why skipping on secondary_dx. have checked spelling errors. don't think method of doing because not work secondary_dx. thing can think of funky since last element of array. has seen before?

edit:
added element(tried both methods, , both resulted in same looking array using print_r:

//array_push($attributenames, "the end"); $attributenames[] ="the end";  echo "<pre>"; print_r($attributenames); echo "</pre>"; 

output along error handling statement above:

array (     [0] => patient mrn     [1] => patient last name     [2] => patient first name     [3] => patient middle name     [4] => patient ssn     [5] => patient sex     [6] => invoice     [7] => transaction     [8] => date of procedure     [9] => posting date     [10] => location     [11] => charge amt     [12] => provider     [13] => fsc1     [14] => fsc2     [15] => patient dob     [16] => attending surgeon     [17] => attending surgeon     [18] => cpt codes     [19] => asa classfication     [20] => anesthesia crna     [21] => anesthesia resident     [22] => surgery start time     [23] => surgery end time     [24] => svc unit     [25] => facility name     [26] => billing number     [27] => billing area name     [28] => procedure modifier1     [29] => procedure modifier2     [30] => procedure modifier3     [31] => primary dx     [32] => secondary dx      [33] => end )   dictionary array array (     [cpt codes] => cpt_code     [asa classfication] => mg_asa_class     [facility name] => facility_name     [billing number] => billing_number     [billing area name] => billing_area_name     [procedure modifier1] => procedure_modifier1     [procedure modifier2] => procedure_modifier2     [primary dx] => primary_dx     [secondary dx] => secondary_dx     [invoice] => fin )   attribute is: cpt_code index is: 18  attribute is: mg_asa_class index is: 19  attribute is: facility_name index is: 25  attribute is: billing_number index is: 26  attribute is: billing_area_name index is: 27  attribute is: procedure_modifier1 index is: 28  attribute is: procedure_modifier2 index is: 29  attribute is: primary_dx index is: 31 error : secondary dx not found array ( [0] => patient mrn [1] => patient last name [2] => patient first name [3] => patient middle name [4] => patient ssn [5] => patient sex [6] => invoice [7] => transaction [8] => date of procedure [9] => posting date [10] => location [11] => charge amt [12] => provider [13] => fsc1 [14] => fsc2 [15] => patient dob [16] => attending surgeon [17] => attending surgeon [18] => cpt codes [19] => asa classfication [20] => anesthesia crna [21] => anesthesia resident [22] => surgery start time [23] => surgery end time [24] => svc unit [25] => facility name [26] => billing number [27] => billing area name [28] => procedure modifier1 [29] => procedure modifier2 [30] => procedure modifier3 [31] => primary dx [32] => secondary dx [33] => end ) array ( [cpt codes] => cpt_code [asa classfication] => mg_asa_class [facility name] => facility_name [billing number] => billing_number [billing area name] => billing_area_name [procedure modifier1] => procedure_modifier1 [procedure modifier2] => procedure_modifier2 [primary dx] => primary_dx [secondary dx] => secondary_dx [invoice] => fin ) attribute is: fin index is: 6 

you should test valid $attributeindex !

 $attributeindex = array_search($index, $attributearray);   if ($attributeindex===false) {     echo "error : ".$index." not found <br />";    } else {      echo "<br>the attribute is: ".$value." index is: ".$attributeindex."<br>";    } 

if not found error can shure $index not found in $attributearray .

update :

this strange !
output can see.
$index == secondary dx

and
$attributearray has key [32]
[32] => secondary dx

only test :
can add $attributearray @ end
[33] => 'end'

and see happens.

update 2 :

as can see in new output got

echo "<pre>"; print_r($attributenames); echo "</pre>"; 

there empty line between [32] , [33].
there must invisible sign @ end of [32] => secondary dx
suspect new line character.

array (     [0] => patient mrn     [1] => patient last name     ....     [30] => procedure modifier3     [31] => primary dx     [32] => secondary dx      [33] => end ) 

try remove character , should work .

tip:

if ever re experiencing similar behavior, should check :

for example:

echo bin2hex($attributenames[32]); 

output in windows @ end :

5345434f4e444152592044580d0a 

where 0d cr = carriage return , 0a lf = line feed .

ascii-tabelle

enter image description here


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -