Forum Moderators: coopster
function conc($v, $w) {
$v .= "this".$w;
return $v;
}
$dog = array("one", "two", "three");
echo array_reduce($dog, "conc");
In PHP4.3.2 the result is "onethistwothisthree".
In PHP4.3.10 the result is "thisonethistwothisthree".
Furthermore, if I do this:
echo array_reduce($dog, "conc", "FIRST");
In PHP4.3.2 the result is "FIRSTthisonethistwothisthree".
In PHP4.3.10 the result is "0thisonethistwothisthree".
...which is even more confusing. There is a zero, not the string "FIRST" being applied to the front of the concatenation.
Which is "correct", and does anybody know why they are different? Is there a new, extra option to select either behaviour?
thanks,
Michael
You might get cross-version consistency if you make your callback function more like:
function conc($v='', $w='') {
$v .= "this".$w;
return $v;
}
That said, have a closer look and maybe put conditional statements in your function for the possibility that one of these args comes in as 'null', or 'false', or doesn't come in at all, so it will always return consistently - I'm not sure that the function as stands will. You might want to make this first do some output to check the types of the arguments coming in.