|
Posted by Ewoud Dronkert on 10/22/12 11:40
torpecool@yahoo.com wrote:
> id | test | result
> 1 | test1 | 50
> | test 2 | 55
> | test 3 | 60
> 2 | test 1 | 10
> | test 2 | 15
> | test 3 | 20
> etc.
>
> When I load this information into the database, it should have this
> format
> id | test 1 | test 2 | test 3
> 1 | 50 | 55 | 60
> 2 | 10 | 15 | 20
$data = file('c:\data\200602\20_001.txt');
$flip = array();
$i = 0;
foreach ( $data as $line )
{
$a = explode("\t", rtrim($line));
if ( $a[0] ) $i = $a[0];
switch ( $a[1] )
{
case 'test 1': $j = 1; break;
case 'test 2': $j = 2; break;
case 'test 3': $j = 3; break;
default: $j = 99;
}
$flip[$i][$j] = $a[2];
}
$flat = array();
foreach ( $flip as $k => $v )
{
$v[0] = $k;
$flat[] = implode("\t", $v);
}
$fh = fopen('c:\data\200602\new_20_001.txt', 'wb');
fwrite($fh, implode("\r\n", $flat)."\r\n");
fclose($fh);
--
E. Dronkert
Navigation:
[Reply to this message]
|