RE: [PHP] Array confusion.
| From: | Altunergil, Oktay | Date: | Thu, 22 Mar 2001 19:53:42 +0000 |
| Subject: | RE: [PHP] Array confusion. | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-45175@lists.php.net to get a copy of this message | ||
You can do this instead..
$month[] = array("Jan","Feb" ......"Dec");
$m = 3;
$real_m = $m-1
echo "Month= $month[$real_m]; //Mar
You can also have PHP assign the first element of the array to index 1
instead of 0.. I think you accomplish that by doing something like $month[]
= array(1=>Jan,Feb,Mar...);
If you need to get the month as $m='03'; you can strip the first zero using
any one of the suitable string functions.
PS: (i noticed that this doesn't really answer your specific question. But
this will work properly for your needs)
oktay
-----Original Message-----
From: Sterling [mailto:smullett@omeninc.com]
Sent: Thursday, March 22, 2001 2:46 PM
To: php-general@lists.php.net
Subject: [PHP] Array confusion.
H-
I'm kinda new to the PHP scene so if the below plea for help is
incredibly simple ... well.. What can I say? I'm stuck.
I've been on the PHP website for the last hour reading the documentation
on arrays and all the functions associated with it but have yet to find
a straight forward explaination on how to accomplish this code.
Here's what I have: (PHP4)
$m = "03";
$list = array(01=>"Jan", 02=>"Feb", 03=>"Mar",
04=>"Apr", 05=>"May",
06=>"Jun", 07=>"Jul", 08=>"Aug", 09=>"Sep\",
10=>"Oct", 11=>"Nov",
12="Dec");
$month = $list[$m];
print "$month\n";
What I want to print is the month in Text format, which in this instance
should be Mar .
I even tried: $month = array_keys($list, $m);
Now I know that $list[x]; references the location of an item so I know
why the previous code doesn't work in that respect, since nowhere is 01
a location but an association within the array. Right?
I've seen examples on printing every element of an array. Printing every
element of a 2d array, poping elements from the beginning and end of an
array but not an example of getting a single element from an array.
I'm sure I'm doing something backwards and might even be confused on how
the array works but don't know what.
If any one has any better solutions to this code please feel free to
post.
Thanks for any assistance anyone can provide.
-Sterling
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
For additional commands, e-mail: php-general-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net