RE: [PHP-GENERAL] Arrays
| From: | php3 at developersdesk dot com | Date: | Mon, 12 Jun 2000 09:55:50 +0000 |
| Subject: | RE: [PHP-GENERAL] Arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-1597@lists.php.net to get a copy of this message | ||
Addressed to: "Roy Nasser" <roy@vem.ca>
"dhaval desai" <dhaval_adams@hotmail.com>
<php-general@lists.php.net>
** Reply to note from "Roy Nasser" <roy@vem.ca> Mon, 12 Jun 2000 02:11:28 -0300
A couple of thoughts...
> If you want to output the name of a day of the week in english you
> can have the following
>
> $name_day[0] = "Sunday";
> $name_day[1] = "Monday";
> $name_day[2] = "Tuesday";
> $name_day[3] = "Wednesday";
> $name_day[4] = "Thursday";
> $name_day[5] = "Firday";
> $name_day[6] = "Saturday";
>
This is the same result with less typing.
$name_day = array( 'Sunday', 'Monday', 'Tuesday',
'Wednesday',
'Thursday', 'Friday', 'Saturday' );
> Hashes can be used for other things and are also very useful...
>
> $car["english"] = "car";
> $car["portuguese"] = "carro";
> $car["french"] = "voiture";
This is the same result with less typing.
$car = array( 'english' => 'car',
'portuguese' => 'carro',
'french' => 'voiture' );
I'm lazy... :)
I also think the arrau() method to initialize an array is easier to
understand, you don't have to look at the mechanics of setting the
array elements, all that is there is the data.
>> I am using mysql as the database.
>> CAn anyone give me an intro to using arrays...and why exactly
>> do we use arrays.
Here is a good one using MySQL. See if you can find the array.
$Result = mysql_Query( "SELECT Field1, Field2 " .
"FROM Table " );
while( list( $Field1, $Field2 ) = mysql_Fetch_Row( $Result )) {
echo( "Field1: $Field1 Field2: $Field2<BR>\n" );
}
That will select field1 and field2 from Table, and paint them, one per
row to the web browser. Do you see an array in there anywhere?
Mysql_fetch_row() returns a number based array of the fields you
request in your SELECT. list() copies the entries into a list of
variables.
Rick Widmer
Internet Marketing Specialists
www.developersdesk.com