note 56234 added to language.types.array
| From: | caifaraaaaatimdooaatbe at osu1 dot php dot net | Date: | Sun, 28 Aug 2005 09:28:09 +0000 |
| Subject: | note 56234 added to language.types.array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-94286@lists.php.net to get a copy of this message | ||
Don't know if this is known or not, but it did eat some of my time and maybe it won't eat
your time now...
I tried to add something to a multidimensional array, but that didn't work at first, look at
the code below to see what I mean:
<?php
$a1 = array( "a" => 0, "b" => 1 );
$a2 = array( "aa" => 00, "bb" => 11 );
$together = array( $a1, $a2 );
foreach( $together as $single ) {
$single[ "c" ] = 3 ;
}
print_r( $together );
/* nothing changed result is:
Array
(
[0] => Array
(
[a] => 0
[b] => 1
)
[1] => Array
(
[aa] => 0
[bb] => 11
)
) */
foreach( $together as $key => $value ) {
$together[$key]["c"] = 3 ;
}
print_r( $together );
/* now it works, this prints
Array
(
[0] => Array
(
[a] => 0
[b] => 1
[c] => 3
)
[1] => Array
(
[aa] => 0
[bb] => 11
[c] => 3
)
)
*/
?>
----
Manual Page -- http://www.php.net/manual/en/language.types.array.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+56234
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56234&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56234&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56234&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56234&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56234&report=yes&reason=non-english
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56234&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+56234&report=yes
Search -- http://master.php.net/manage/user-notes.php