note 76779 added to function.array-reduce
| From: | JanezR dot at osu1 dot php dot net | Date: | Mon, 30 Jul 2007 15:27:15 +0000 |
| Subject: | note 76779 added to function.array-reduce | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-129048@lists.php.net to get a copy of this message | ||
--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;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 86.61.77.143
----
Manual Page -- http://www.php.net/manual/en/function.array-reduce.php
Edit -- https://master.php.net/note/edit/76779
Del: integrated -- https://master.php.net/note/delete/76779/integrated
Del: useless -- https://master.php.net/note/delete/76779/useless
Del: bad code -- https://master.php.net/note/delete/76779/bad+code
Del: spam -- https://master.php.net/note/delete/76779/spam
Del: non-english -- https://master.php.net/note/delete/76779/non-english
Del: in docs -- https://master.php.net/note/delete/76779/in+docs
Del: other reasons-- https://master.php.net/note/delete/76779
Reject -- https://master.php.net/note/reject/76779
Search -- https://master.php.net/manage/user-notes.php