I have built a configuration utility for our users to "tell" us how their file
is configured (formatted). The default format of the configuration is
[pre]1|2|3|4|5|6|7[/pre] where the numbers represent the position of our database
columns in reference to the columns in their file. For instance, this is
our default column layout that matches the above format:
[pre]PartNo,AltPartNo,CondCode,Qty,Descr[/pre]
Now, if a customer has a file formatted like this:
[pre]PartNo,Descr,Qty,NSN,CondCode,AltPartNo,Manuf[/pre]
Their numbering would be [pre]1|5|4|6|3|2|7[/pre]
Note: I am allowing them to have at least 2 columns extra in their format.
Here is the code I'm using to "rearrange" the field data to the format we
need it to be in:
$input = array("TNC01FTNG", "CONNECTOR" , 790 ,"N/A1" ,"NS" ,"N/A2" ,"NONE");
$format = array(1,5,4,6,3,2,7);
while ($index = current($format)) {
$result[] = $input[$index-1];
next($format);
}
echo "Before:PartNo,Descr,Qty,NSN,CondCode,Alt,Manuf<br>";
print_r($input);
echo "<br>After:PartNo,Alt,CondCode,Qty,Descr<br>";
print_r($result);
echo "<br>Format:";
print_r($format);
Results:
Before:PartNo,Descr,Qty,NSN,CondCode,Alt,Manuf
Array([0]=>TNC01FTNG [1]=>CONNECTOR [2]=>790 [3]=>N/A1 [4]=>NS [5]=>N/A2 [6]=>NONE)
After:PartNo,Alt,CondCode,Qty,Descr
Array([0]=>TNC01FTNG [1]=>NS [2]=>N/A1 [3]=>N/A2 [4]=>790 [5]=>CONNECTOR [6]=>NONE)
Format: Array([0]=>1[1]=>5[2]=>4[3]=>6[4]=>3[5]=>2[6]=>7)
For some reason, it is not doing things exactly like I'd expect.
It is not putting the data in the correct order.
This is what $result needs to be:
Array([0]=>TNC01FTNG [1]=>N/A2 [2]=>NS [3]=>790 [4]=>CONNECTOR [5]=>N/A1 [6]=>NONE)
Can anyone help out here, I can't see the forest for the trees, here...