I want to know how to pass more arguments to my array_walk..
$addresses = array('www.google.com', 'www.yahoo.com', 'www.microsoft.com');
$a = 'hey';
$b = 'hey';
array_walk($addresses, array($this, '_handle'), $a, $b); // $a and $b parameters doesn't get passed
private function _handle($address,$a, $b) {
echo $address; // www.google.com
echo $a // 012
echo $b // 012
}
How do I pass parameters anyway? I have to pass more than 5 parameters.. please teach me.. thanks!
You can use the use
keyword with an anonymous function like this:
Note: $custom_var is a mixed datatype so can be an array if you want to pass several values
$custom_var = 'something';
array_walk(
$array,
function( &$value, $key) use ( $custom_var ){
// Your code here, you can access the value of $custom_var
});
It will only allow one argument for user data. I suggest passing your values as an array.
array_walk($addresses, array($this, '_handle'), array($a, $b));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With