note 76777 added to function.array-reduce

From: Date: Mon, 30 Jul 2007 15:05:19 +0000
Subject: note 76777 added to function.array-reduce
Groups: php.notes 
Request: Send a blank email to php-notes+get-129046@lists.php.net to get a copy of this message
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; } ?> ---- Server IP: 213.250.2.28 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/76777 Del: integrated -- https://master.php.net/note/delete/76777/integrated Del: useless -- https://master.php.net/note/delete/76777/useless Del: bad code -- https://master.php.net/note/delete/76777/bad+code Del: spam -- https://master.php.net/note/delete/76777/spam Del: non-english -- https://master.php.net/note/delete/76777/non-english Del: in docs -- https://master.php.net/note/delete/76777/in+docs Del: other reasons-- https://master.php.net/note/delete/76777 Reject -- https://master.php.net/note/reject/76777 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#129046) next »