PHP Associative Array Duplicate Key?
Posted
by Steven
on Stack Overflow
See other posts from Stack Overflow
or by Steven
Published on 2010-05-21T01:54:49Z
Indexed on
2010/05/21
2:00 UTC
Read the original article
Hit count: 342
php
Hello,
I have an associative array, however when I add values to it using the below function it seems to overwrite the same keys. Is there a way to have multiple of the same keys with different values? Or is there another form of array that has the same format?
I want to have 42=>56 42=>86 42=>97 51=>64 51=>52 etc etc
function array_push_associative(&$arr) {
$args = func_get_args();
foreach ($args as $arg) {
if (is_array($arg)) {
foreach ($arg as $key => $value) {
$arr[$key] = $value;
$ret++;
}
}else{
$arr[$arg] = "";
}
}
return $ret;
}
© Stack Overflow or respective owner