Re: Question for PHP Arrays
| From: | Richard Davey | Date: | Fri, 28 Apr 2006 15:35:22 +0000 |
| Subject: | Re: Question for PHP Arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235018@lists.php.net to get a copy of this message | ||
On 27 Apr 2006, at 20:51, Saul Rennison wrote:
Anyway, I want to know how to add things to an array. Like this: $foobar = array() $foobar['rar']['miaw'] Would that output come out (for the array) as: array( 'rar' => 'miaw' )No, it would create a multi-dimensional array that contains nothing. You want: $foobar['rar'] = 'miaw';
Please correct me if wrong. Also I need to ask one more question, would this work: $foobar = array() function addToArray($int, $value) { $foobar[$int][$value] } And with a function call addToArray(1, "meow") output as the array looking like: array( '1' => 'meow' )No (because of the mistake commented on above). However another issue at play here is scope. $foobar the array will not be visible to the function addToArray unless you make it global. Cheers, Rich -- http://www.corephp.co.uk Zend Certified Engineer PHP Development Services