[PHP] array confusion...

2003-11-24 Thread Dan Joseph
Hi,

I must be missing something in this array.  To me this makes no sense.
Here is it broken down...

Declartion:

$gtotals = array(
CO1 = 0,
CO2 = 0,
CO3 = 0,
CO4 = 0,
CO5 = 0,
CO6 = 0,
CO7 = 0
);

Code run:

while ( list( $action_code, $date_created, $date_letter_send ) =
mysql_fetch_row( $raw_res ) )
{
if ( $action_code == 'C01' || $action_code == 'C02' ||
 $action_code == 'C03' || $action_code == 'C04' ||
 $action_code == 'C05' || $action_code == 'C06' ||
 $action_code == 'C07' 
)
{

$totals[$date_created][$action_code]['created_count']++;
$gtotals[$action_code]++;
$dgtotals[$date_created]++;
$ggtt++;
$count++;
}
}

print_r results:

Array
(
[CO1] = 0
[CO2] = 0
[CO3] = 0
[CO4] = 0
[CO5] = 0
[CO6] = 0
[CO7] = 0
[C01] = 15
[C02] = 40
[C03] = 50
[C04] = 4
[C05] = 4
)

Now, the problem I'm having is that when I echo $array['C06'] and
$array['C07'] I'm getting  (nothing..).  Could someone point out how this
can be, and what I've done wrong?

-Dan Joseph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] array confusion...

2003-11-24 Thread Brad Pauly
On Mon, 2003-11-24 at 13:42, Dan Joseph wrote:
 Hi,
 
   I must be missing something in this array.  To me this makes no sense.
 Here is it broken down...
 
   Declartion:
 
   $gtotals = array(
   CO1 = 0,
   CO2 = 0,
   CO3 = 0,
   CO4 = 0,
   CO5 = 0,
   CO6 = 0,
   CO7 = 0
   );
 

[snip]

 
   print_r results:
 
   Array
   (
   [CO1] = 0
   [CO2] = 0
   [CO3] = 0
   [CO4] = 0
   [CO5] = 0
   [CO6] = 0
   [CO7] = 0
   [C01] = 15
   [C02] = 40
   [C03] = 50
   [C04] = 4
   [C05] = 4
   )
 
   Now, the problem I'm having is that when I echo $array['C06'] and
 $array['C07'] I'm getting  (nothing..).  Could someone point out how this
 can be, and what I've done wrong?

I think you might have some letter 'O's instead of the number 0. Notice
that you have CO1 and C01 when you print_r. They are different keys.

- Brad

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] array confusion...

2003-11-24 Thread Dan Joseph
Hi,

 I think you might have some letter 'O's instead of the number 0. Notice
 that you have CO1 and C01 when you print_r. They are different keys.

I think you are correct!  hahaha...  oh man, one of those Mondays!  Thank
you sir!

-Dan Joseph

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] Array confusion.

2001-03-22 Thread Sterling

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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array confusion.

2001-03-22 Thread CC Zona

In article [EMAIL PROTECTED],
 [EMAIL PROTECTED] (Sterling) wrote:

  $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?

The keys to an associative array should be quoted.  Also, that escaped 
quote on "Sep\" is throwing everything off.  Try:

 $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");//keys quoted, no escaped quotes
 $month = $list["$m"];//associative array element index quoted
 print "$month\n";

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Array confusion.

2001-03-22 Thread Altunergil, Oktay

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:[EMAIL PROTECTED]]
Sent: Thursday, March 22, 2001 2:46 PM
To: [EMAIL PROTECTED]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Array confusion.

2001-03-22 Thread Sterling

H-

Thanks to all that wrote in with input on this issue. 

I really appreciate the assistance. 

Thanks to CC Zona and James for the code sample. It looks like there
were typo's in my code and it threw me for a minute after
recieving/applying all the emails. 
That backslash wasn't suppose to be in the original email I sent out, it
was just from my Emacs window wrapping and the = next to Dec became a
problem after I quoted everything else but I found it eventually.

Thanks again. It's now working as I expected it too. 
-Sterling


CC Zona wrote:
 
 In article [EMAIL PROTECTED],
  [EMAIL PROTECTED] (Sterling) wrote:
 
   $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?
 
 The keys to an associative array should be quoted.  Also, that escaped
 quote on "Sep\" is throwing everything off.  Try:
 
  $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");//keys quoted, no escaped quotes
  $month = $list["$m"];//associative array element index quoted
  print "$month\n";
 
 --
 CC
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]