Re: array_push problem
| From: | Matthew Kendall | Date: | Thu, 17 Aug 2000 05:42:36 +0000 |
| Subject: | Re: array_push problem | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-1885@lists.php.net to get a copy of this message | ||
"Cong Thanh Nguyen" <congnguyen@psv.com.vn> wrote ...
> I have an array with 2 elements :
> $a = array(a=>"aaaaaaa",b=>"bbbbbbbbb");
> I want to add new elements: c=>"ccccc" by using
> array_push function or another method.
You do not need array_push() for this; you can add a new element to the end
of an existing array simply by setting it:
$a = array('a' => 'aaaaaaa', 'b' => 'bbbbbbbbb');
$a['c'] = 'ccccc'; // now $a has three elements.
Incidentally, you should refer to the elements in your example using quoted
strings. If you turn error_reporting up to 15 you will see that without the
quotes you have some warnings. And single quotes will work fine; you do not
need double quotes because there is no need to parse the string.