Connecting Tech Pros Worldwide Forums | Help | Site Map

What is the purpose of an array?

Joel Farris
Guest
 
Posts: n/a
#1: Jul 17 '05
I've just finished reading Kevin Yank's book "Build Your Own Database Driven
Website", and I've not quite got a handle on the array variable.

Why do I need an array? Give me an example of an array in use, so that I can
understand why I'd want to store a bunch of stuff in one variable.
--
Joel Farris | Q: It reverses the logical flow of conversation.
twinkledust Designs | A: Why is top posting frowned upon?
http://twinkledust.com|
AIM chat: FarrisJoel | "John Kerry: A walking, talking contradiction"


steve
Guest
 
Posts: n/a
#2: Jul 17 '05

re: What is the purpose of an array?


"Joel Farris" wrote:[color=blue]
> I’ve just finished reading Kevin Yank’s book "Build Your
> Own Database Driven
> Website", and I’ve not quite got a handle on the array variable.
>
> Why do I need an array? Give me an example of an array in use, so[/color]
that[color=blue]
> I can
> understand why I’d want to store a bunch of stuff in one
> variable.[/color]

Joel,
There are a ton of resources on the net about php arrays. Try this
and you should find a ton of stuff:
http://www.google.com/search?sourcei...array+tutorial

--
http://www.dbForumz.com/ This article was posted by author's request
Articles individually checked for conformance to usenet standards
Topic URL: http://www.dbForumz.com/PHP-purpose-...ict132976.html
Visit Topic URL to contact author (reg. req'd). Report abuse: http://www.dbForumz.com/eform.php?p=444088
Geoff Berrow
Guest
 
Posts: n/a
#3: Jul 17 '05

re: What is the purpose of an array?


I noticed that Message-ID:
<SAGMc.320002$Gx4.107380@bgtnsc04-news.ops.worldnet.att.net> from Joel
Farris contained the following:
[color=blue]
>I've just finished reading Kevin Yank's book "Build Your Own Database Driven
>Website", and I've not quite got a handle on the array variable.
>
>Why do I need an array? Give me an example of an array in use, so that I can
>understand why I'd want to store a bunch of stuff in one variable.[/color]


A 'please' would be nice.

Say you have a number of inputs which you wish to validate. As you
validate each field it either passes or fails. If it fails you store
the field name in an array. At the end of the process you extract the
values in the array using a loop and display them.

The more code you write, the more obvious it will be.
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Joel Farris
Guest
 
Posts: n/a
#4: Jul 17 '05

re: What is the purpose of an array?


Geoff Berrow wrote:
[color=blue]
> A 'please' would be nice.[/color]

please() ;
[color=blue]
> Say you have a number of inputs which you wish to validate. As you
> validate each field it either passes or fails. If it fails you store
> the field name in an array. At the end of the process you extract the
> values in the array using a loop and display them.
>
> The more code you write, the more obvious it will be.[/color]


AHA! I was googling a bit and didn't really get a handle on it. I thought they
were saying that I should use arrays to store stuff in place of a database table
and I'm thinking, "Well, why shouldn't I just use a table?"

Your example makes it immediately obvious. Thanks.
--
Joel Farris | Q: It reverses the logical flow of conversation.
twinkledust Designs | A: Why is top posting frowned upon?
http://twinkledust.com|
AIM chat: FarrisJoel | "John Kerry: A walking, talking contradiction"

Gordon Burditt
Guest
 
Posts: n/a
#5: Jul 17 '05

re: What is the purpose of an array?


>> Say you have a number of inputs which you wish to validate. As you[color=blue][color=green]
>> validate each field it either passes or fails. If it fails you store
>> the field name in an array. At the end of the process you extract the
>> values in the array using a loop and display them.
>>
>> The more code you write, the more obvious it will be.[/color]
>
>
>AHA! I was googling a bit and didn't really get a handle on it. I thought they
>were saying that I should use arrays to store stuff in place of a
>database table
>and I'm thinking, "Well, why shouldn't I just use a table?"[/color]

An array (especially an associative array) is a logical place to
PUT stuff from a database table after a query on the database while
you're getting ready to use the result. For example, mysql_fetch_row()
returns an array with the data from one row in it.

Also, some data is intermediate results and temporary: there's no
need to save anything but the final results, and many of the final
results go to the user's browser, not a database.

In some cases, you can think of an array (especially an associative
array, as PHP has) as an in-memory database. Consider things like
$_GET, $_PUT, $_SERVER, etc. With single variables you can't get
a list of which variables were passed. With a PHP array, you can.
The array $_SESSION is in-memory while it's being used, but between
pages, it gets saved somewhere else (a disk file is the default; I
prefer to use different session handlers to put it in a database
instead. Among other things, garbage collection is easier).
[color=blue]
>Your example makes it immediately obvious. Thanks.[/color]

Gordon L. Burditt
Michael Austin
Guest
 
Posts: n/a
#6: Jul 17 '05

re: What is the purpose of an array?


Joel Farris wrote:
[color=blue]
> Geoff Berrow wrote:
>[color=green]
>> A 'please' would be nice.[/color]
>
>
> please() ;
>[color=green]
>> Say you have a number of inputs which you wish to validate. As you
>> validate each field it either passes or fails. If it fails you store
>> the field name in an array. At the end of the process you extract the
>> values in the array using a loop and display them.
>>
>> The more code you write, the more obvious it will be.[/color]
>
>
>
> AHA! I was googling a bit and didn't really get a handle on it. I
> thought they were saying that I should use arrays to store stuff in
> place of a database table and I'm thinking, "Well, why shouldn't I just
> use a table?"[/color]

that will all depend on what you are going to do with the data. is it long term
information or short term and does it need to persist beyond the current viewing
of the page and need to remain server-side and not disclosed to the client.
there are ways to do this not using a database as well.
[color=blue]
>
> Your example makes it immediately obvious. Thanks.[/color]


--
Michael Austin.
Consultant - Available in 2-3 weeks.
Donations welcomed. Http://www.firstdbasource.com/donations.html
:)
Closed Thread