Talk:Associative array/Creation: Difference between revisions
Content added Content deleted
m (Response to anonymous.) |
No edit summary |
||
Line 7: | Line 7: | ||
Why does Perl have two separate sections? |
Why does Perl have two separate sections? |
||
:Looks like sloppy editing, perhaps on my part. I didn't check who submitted it, I just removed the less-well-formed entry. --[[User:Short Circuit|Short Circuit]] 10:06, 25 January 2007 (EST) |
:Looks like sloppy editing, perhaps on my part. I didn't check who submitted it, I just removed the less-well-formed entry. --[[User:Short Circuit|Short Circuit]] 10:06, 25 January 2007 (EST) |
||
== PHP == |
|||
I don't know if it is relevant, but should we add user-made functions ? I know I often use a hand made function because it's really convenient... Anyway, here is the PHP Manual version, dunno if it should be added: |
|||
<? |
|||
// Append associative array elements |
|||
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; |
|||
} |
|||
It's like [[http://fr2.php.net/array_push array_push ()]], up to the part that it actually allows associative elements to be added (pushed)... More info: http://fr2.php.net/manual/en/function.array-push.php#58705 |