hi, i got any array:
$arrname = array('1234'=>'chris', '5678'=>'john');
to add a item to an existing array, it can be done this way:
$arrname['9101']='mary'
$arrname['1213']='foo';
//printout
Array
(
[1234] => chris
[5678] => john
[9101] => mary
[1213] => foo
)
however, if i add items dynamically, like this it wont work:
function uniqueid($str,$hashstring)
{
$hash=md5($str.$hashstring);
return $hash;
}
$hash=uniqueid(date('Y-m-d h:i:s:u'),'key');
$arrname[$hash]=date('Y-m-d h:i:s:u');
//printout
Array
(
[1234] => chris
[5678] => john
[9101] => mary
[1213] => foo
[aa3b94089747eaf8177cd60c22a51542] => 2008-10-07 12:46:20:000000
)
then each time i print out, it will not add an additional key with its value. Instead, it overwrite the last key and value:
//printout
Array
(
[1234] => chris
[5678] => john
[9101] => mary
[1213] => foo
[7ecb2c22ccfd893800e9932b0df2cb38] => 2008-10-07 12:48:29:000000
)
My obj is to add items into the array using unique key with some value like this:
Array
(
[1234] => chris
[5678] => john
[9101] => mary
[1213] => foo
[aa3b94089747eaf8177cd60c22a51542] => 2008-10-07 12:46:20:000000
[7ecb2c22ccfd893800e9932b0df2cb38] => 2008-10-07 12:48:29:000000
)
how should i do this?
thks