note 76777 deleted from function.array-reduce by derick
| From: | derick@php.net | Date: | Wed, 20 Feb 2008 13:04:58 +0000 |
| Subject: | note 76777 deleted from function.array-reduce by derick | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-136310@lists.php.net to get a copy of this message | ||
Note Submitter: Janez R.
----
In PHP ver. 4.3.1 the initial value parameter allowed for string type also. In PHP ver. 5.1.6 this
param is now converted to int and callback function will receive number 0 when initial param his an
empty string.
<?php
function arc ($reduced, $item)
{
$reduced = $item.$reduced;
return $reduced;
}
arc( array(a,b,c), "arc", "" );
?>
Output in PHP 4.3.1: cba
Output in PHP 5.1.6: cba0
Possible solution:
<?php
function arc ($reduced, $item)
{
if ($reduced === 0) $reduced = "";
$reduced = $item.$reduced;
return $reduced;
}
?>