This is Interesting: Free Magazines for Graphics designers and webmasters
Home > Archive > Webmaster forum > September 2006 > Hey Grey you around???
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Hey Grey you around???
|
|
| Patrick 2006-09-24, 6:58 pm |
| Grey,
I have another PHP question for the guru if you don't mind taking a
look. Hopefully you or someone can point me in the right direction. No
smarties. I already tried at the PHP group, but no one was home.
I have numerous files that look like the chunk below. From the date and
time, I calculate a year day value. For example the value for this file
is 148.67721064815
I'm not an expert yet at dealing with arrays, but I'm getting around
well in PHP otherwise (reading data files, loops, functions, etc). I
already have loops set up to read the files and data and I can output it
to a web page. I just found that I am going to have to read it all into
an array for further grooming, which I can do, but not in the way I want to.
My question is how would I go about creating an array that would hold
the year day as a key and the entire file contents in the next element?
Then when I advance to the next file do the same thing so that my ending
array would come out something like this;
[yearday file1][file1 contents]
[yearday file2][file2 contents]
[yearday file3][file3 contents]
....
...
..
Or is what I am wanting to do out of the question?
Appreciate your help.
Patrick
File example;
Descent 27.4279 -83.0965 05-29-06 16:15:11 55.052 26.52 0.95 35.28
Descent 27.4279 -83.0965 05-29-06 16:15:11 55.014 26.51 1.95 35.26
Descent 27.4279 -83.0965 05-29-06 16:15:11 55.047 26.50 3.04 35.29
Descent 27.4279 -83.0965 05-29-06 16:15:11 54.957 26.47 4.29 35.24
Descent 27.4279 -83.0965 05-29-06 16:15:11 54.947 26.45 5.33 35.25
Descent 27.4279 -83.0965 05-29-06 16:15:11 54.871 26.41 6.42 35.22
Descent 27.4279 -83.0965 05-29-06 16:15:11 54.875 26.36 7.52 35.25
Descent 27.4279 -83.0965 05-29-06 16:15:11 54.884 26.30 8.65 35.31
Descent 27.4279 -83.0965 05-29-06 16:15:11 54.887 26.24 9.78 35.35
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - college of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334
The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
| |
| GreyWyvern 2006-09-24, 6:58 pm |
| And lo, Patrick didst speak in alt.www.webmaster:
> Grey,
Tsk, tsk. Personal messages in a newsgroup?
> I have numerous files that look like the chunk below. From the date an=
d =
> time, I calculate a year day value. For example the value for this fil=
e =
> is 148.67721064815
You want to store all that precision as well?
> My question is how would I go about creating an array that would hold =
=
> the year day as a key and the entire file contents in the next element=
? =
> Then when I advance to the next file do the same thing so that my endi=
ng =
> array would come out something like this;
>
> [yearday file1][file1 contents]
> [yearday file2][file2 contents]
> [yearday file3][file3 contents]
> ...
> ..
> .
It's simply a matter of telling the variable that's how you want it to =
be. Although, if you're going to keep all those decimal points, I =
recommend storing the yearday key as a string so it isn't confused with =
=
PHP's normal integer numbering of arrays.
while ([incoming file]) {
// ... extract file contents and calculate yearday value
$data[(string)$yearday] =3D $contents;
}
Then you can use functions such as ksort() <http://www.php.net/ksort> to=
=
sort the array accoding to key.
> Or is what I am wanting to do out of the question?
Associative arrays (the term for the type of array you want to build) is=
=
an integral part of most high-level programming languages :)
Grey
-- =
The technical axiom that nothing is impossible sinisterly implies the =
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured =
spider and site-search engine
| |
| Patrick 2006-09-24, 6:58 pm |
| GreyWyvern wrote:
> And lo, Patrick didst speak in alt.www.webmaster:
>
>
>
> Tsk, tsk. Personal messages in a newsgroup?
Well I tried spam at greywyvern.com but it didn't work. Not really.
>
>
>
> You want to store all that precision as well?
>
Yep I'm going to need it.
>
>
> It's simply a matter of telling the variable that's how you want it to
> be. Although, if you're going to keep all those decimal points, I
> recommend storing the yearday key as a string so it isn't confused with
> PHP's normal integer numbering of arrays.
>
> while ([incoming file]) {
>
> // ... extract file contents and calculate yearday value
>
> $data[(string)$yearday] = $contents;
> }
>
> Then you can use functions such as ksort() <http://www.php.net/ksort>
> to sort the array accoding to key.
>
>
>
> Associative arrays (the term for the type of array you want to build)
> is an integral part of most high-level programming languages :)
>
> Grey
>
Thanks for the pointers. I'll see what I can do.
Patrick
--
Patrick A. Smith Assistant System Administrator
Ocean Circulation Group – USF - college of Marine Science
http://ocgweb.marine.usf.edu Phone: 727 553-3334
The trouble with doing something right the first time is that nobody
appreciates how difficult it was. - La Rochefoucauld
| |
| Toby Inkster 2006-09-24, 6:59 pm |
| GreyWyvern wrote:
> Associative arrays (the term for the type of array you want to build) is
> an integral part of most high-level programming languages :)
PHP, Perl, and... err... umm... ahh... ;-)
--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact
| |
| GreyWyvern 2006-09-24, 6:59 pm |
| And lo, Toby Inkster didst speak in alt.www.webmaster:
> GreyWyvern wrote:
>
>
> PHP, Perl, and... err... umm... ahh... ;-)
Off the top of my head: PHP, Perl, Javascript, C++, Python, Ruby, Lisp and
Lua. They are not always called "associative arrays" in these languages,
but they are there with similar functionality in each.
Grey
--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
|
|
|
| | Copyright 2003 - 2008 forum4designers.com Software forum Computer Hardware reviews |
|