note 81472 deleted from language.types.type-juggling by nlopess
| From: | nlopess@php.net | Date: | Fri, 29 Feb 2008 17:21:12 +0000 |
| Subject: | note 81472 deleted from language.types.type-juggling by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-136601@lists.php.net to get a copy of this message | ||
Note Submitter: cpartiot at wanadoo dot fr
----
array_sum2() :
Fonction équivalente à array_sum,mais récursive :
<?php
function array_sum2($tab)
{
if(!is_array($tab))
return floatval($tab);
$ret=0;
foreach($tab as $val)
{
if(is_array($val))
$ret+=array_sum2($val);
else
$ret+=$val;
}
return $ret;
}
?>
test :
<?php
$tab=array(array(1,2,3) , array("4",5) , 6 , "abc" , 7) ;
echo array_sum2($tab);
?>
Sortie :
28