PHP Associative Array Duplicate Keys -
i have associative array, when add values using below function seems overwrite same keys. there way have multiple of same keys different values? or there form of array has same format?
i want have:
42=>56 42=>86 42=>97 51=>64 51=>52 etc etc
code:
function array_push_associative(&$arr) { $args = func_get_args(); foreach ($args $arg) { if (is_array($arg)) { foreach ($arg $key => $value) { $arr[$key] = $value; $ret++; } }else{ $arr[$arg] = ""; } } return $ret; }
no, cannot have multiple of same key in associative array.
you could, however, have unique keys each of corresponding values arrays, , arrays have multiple elements each key.
so instead of this...
42=>56 42=>86 42=>97 51=>64 51=>52
...you have this:
array ( 42 => array ( 56, 86, 97 ) 51 => array ( 64, 52 ) )
Comments
Post a Comment