Reply to Re: Tricky explode(), help please!

Your name:

Reply:


Posted by Ewoud Dronkert on 10/27/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

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация