note 108996 modified in function.array-walk by danbrown
| From: | danbrown@php.net | Date: | Wed, 13 Jun 2012 15:27:44 +0000 |
| Subject: | note 108996 modified in function.array-walk by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-188575@lists.php.net to get a copy of this message | ||
####### I intuitively tried to use array_walk function with PHP built-in function
"abs($var)" but it did not work and got some warning
message <?php $values =
array(-5,2,3,-8,4,-1,0); array_walk($values,
"abs"); ?> =>
Warning: abs() expects exactly 1 parameter, 2 given in ... ######
Then I wrote this function
: <?php function
myAbs(&$val){ 	$val =
abs($val); } array_walk($values,
"myAbs"); ?> ##### It
works!
--was--
####### I intuitively tried to use array_walk function with PHP built-in function
"abs($var)" but it did not work and got some warning message
$values = array(-5,2,3,-8,4,-1,0);
array_walk($values, "abs");
=> Warning: abs() expects exactly 1 parameter, 2 given in ...
###### Then I wrote this function :
function myAbs(&$val){
$val = abs($val);
}
array_walk($values, "myAbs");
##### It works!
http://php.net/manual/en/function.array-walk.php