I am writing a utility to do some data loading from text files. I have a collection of dictionary files that i am processing into arrays that define the structure of the data files. Yes, i could use classes or otherwise, but using arrays, i have been stumped.
Let's say i have 3 files that i read and load into arrays. When i read the arrays, the 3rd instance has elements of the second despite trying to use unset and other things. What am I missing? I am on cygwin using php 5.3.16
Following are examples of list, but not the real lists. so, please disregard the substr statements as they are not real
fname c 1 16
lname c 17 30
addr c 1 20
city c 21 30
state c 31 40
zip n 41 45
bday d 1 9
ssn c 10 18
when loading with the code below, the 3rd array has elements from the second, namely bday, ssn, state and zip.
$cnt = 0;
while ($s = fgets($fp, 1024)) {
$fldprops = array();
$fldprops[0] = trim(substr($s,0,8));
$fldprops[1] = trim(substr($s,9,1));
$fldprops[2] = trim(substr($s,11,3));
$fldprops[3] = trim(substr($s,15,3));
$flds[$cnt] = $fldprops;
$cnt++;
unset($fldprops);
}
I had thought either one of $fldprops = array(); or unset() would clear the array but it is not working.
Update: I mistook the point of failure. it is not apparently at writing to the outer array, but in reading. As i mentioned in a comment, later in the code, i have a foreach loop and here it is failing:
foreach ($flds as $fldprop) {
var_dump($fldprop);
}
here, i get bday, ssn, state and zip (the last two entries of the second array merged with the 3rd array).
$s?$fldprops = array()creates a new empty array, so how do you determine that it's not working?field. I'm sure that's it.