Re: [PHP] Adding elements to an array

2001-07-17 Thread Patrik Wallstrom

On Tue, 17 Jul 2001, Sharat Hegde wrote:

> Hello,
>
> I have a requirement to add elements to an associate array dynamically based
> on some conditions. I initialize the array with the 1st associate array
> element
>   $MyArray = array('DATETIME' => $DateTime);
>
> How do I add more elements to this associate array. I am using PHP 3 and
> array_merge and other functions for arrays are not supported in PHP3. I am
> trying the following:
>   $MyArray[] = array("BUYVAL" => "1.23");
> but if I try and get the value of $MyArray[BUYVAL], I get nothing.

What you have done here is that you have added an array to your array, but
you wished to have the value added to your array. The $MyArray[] pushes a
new value to the array, in this case another array. You want
$MyArray['BUYVAL'] = 1.23.

More info on arrays from the php docs:
http://php.net/manual/en/language.types.array.php

--
 patrik wallstrom |  f o o d f i g h t
 tel: +46-8-6188428   |  s t o c k h o l m
 gsm: +46-708405080   |  - - - - - - - - -


-- 
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] Adding elements to an array

2001-07-17 Thread Adrian Ciutureanu

$MyArray['BUYVAL'] = 1.23;

> -Original Message-
> From: Sharat Hegde [mailto:[EMAIL PROTECTED]]
> Sent: 17 iulie 2001 13:11
> To: [EMAIL PROTECTED]
> Subject: [PHP] Adding elements to an array
> 
> 
> Hello,
> 
> I have a requirement to add elements to an associate array 
> dynamically based
> on some conditions. I initialize the array with the 1st 
> associate array
> element
>   $MyArray = array('DATETIME' => $DateTime);
> 
> How do I add more elements to this associate array. I am 
> using PHP 3 and
> array_merge and other functions for arrays are not supported 
> in PHP3. I am
> trying the following:
>   $MyArray[] = array("BUYVAL" => "1.23");
> but if I try and get the value of $MyArray[BUYVAL], I get nothing.
> 
> I am sure this must be simple, but I do not seem to be 
> getting it right!!
> 
> Regards,
> Sharat Hegde
> Phone: 6560360 Ext 4680
> 
> 
> -- 
> 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]




[PHP] Adding elements to an array

2001-07-17 Thread Sharat Hegde

Hello,

I have a requirement to add elements to an associate array dynamically based
on some conditions. I initialize the array with the 1st associate array
element
$MyArray = array('DATETIME' => $DateTime);

How do I add more elements to this associate array. I am using PHP 3 and
array_merge and other functions for arrays are not supported in PHP3. I am
trying the following:
$MyArray[] = array("BUYVAL" => "1.23");
but if I try and get the value of $MyArray[BUYVAL], I get nothing.

I am sure this must be simple, but I do not seem to be getting it right!!

Regards,
Sharat Hegde
Phone: 6560360 Ext 4680


-- 
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]