note 76779 deleted from function.array-reduce by levim
| From: | levim@php.net | Date: | Mon, 24 Feb 2014 16:24:11 +0000 |
| Subject: | note 76779 deleted from function.array-reduce by levim | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-198629@lists.php.net to get a copy of this message | ||
Note Submitter: Janez R.
----
--REPOST, fixed some typos, please replace previous note--
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 is an
empty string.
<?php
function arc ($reduced, $item)
{
$reduced = $item.$reduced;
return $reduced;
}
array_reduce( 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;
}
?>