You are here: Re: [PHP] Breaking up data efficiently « PHP « IT news, forums, messages
Re: [PHP] Breaking up data efficiently

Posted by Philip Hallstrom on 06/28/05 03:02

On Tue, 28 Jun 2005, Wee Keat wrote:

> Hi All,
>
> I'm working on an aircraft booking system and it has multiple
> origin/destination data, concatenated into a single line:
>
>
> /***** BEGIN DATA *****/
>
> Melbourne, AU, 21-07-2005 14:00:00|Perth, AU, 21-07-2005 18:00:00|Perth,
> AU, 25-07-2005 14:00:00|Melbourne, AU, 25-07-2005 18:00:00
>
> /***** END DATA *****/
>
>
> As you can see, each origin/destination is separated by a pipe '|', and
> then, each origin/destination data has its location, country and
> datetime of departure/arrival, separated by comma ','.
>
> I'm splitting them up into array of location, country and datetime using
> the following:
>
>
> /***** BEGIN CODE *****/
>
> $itenary = explode('|', $booking->booking_flight_details);
>
> $size = count($itenary);
>
> for($i=0; $i < $size; $i++) {
> list($path[$i]['location'],
> $path[$i]['country'],
> $path[$i]['datetime']) = explode(',', $itenary[$i]);
> }
>
> /***** END CODE *****/
>
>
>
> *Question*: Is the above the code an effective way to do it? Or is there
> a better/faster way?

I suppose it depends on how many records you're going to have to split
up... here's another way, but I don't know if it's faster -- I'll let you
time it -- and it's certainly not as readable...

$bits = split("[|,]", $booking->booking_flight_details);
$size = count($itenary);
for ( $i = 0; $i < $size; $i += 3 ) {
$path[$i]['location'] = $bits[$i];
$path[$i]['country'] = $bits[$i + 1];
$path[$i]['datetime'] = $bits[$i + 2];
}

 

Navigation:

[Reply to this 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

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