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 |
Revision as of 11:29, 2 July 2007
This info seems to be the as in Create a Hash, I'd like to flag this for possible removal
- It looks like there's some duplication in the code examples, but the way the tasks are defined, they really address different things. (Despite the title of Create a Hash.)
- Still, I'm going to move the contents of Create a Hash into Creating an Associative Array, with annotations where the behavior differs. (It's added behavior, not alternate behavior. I'm comfortable with that, for now.) --Short Circuit 13:46, 23 January 2007 (EST)
- Done. Content from Create a Hash has been moved to here. ("Associative Array" is a more generic term.) --Short Circuit 12:19, 24 January 2007 (EST)
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. --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 [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