Voting

: nine minus eight?
(Example: nine)

The Note You're Voting On

mystral77 at gmail dot com
4 years ago
Hello,

If you want to add values with same key from two arrays :

<?php
function add(&$item,$key,$search) {
$item += (is_array($search))?((isset($search[$key]))?$search[$key]:0):0;
}

$a = ["orange" => 2, "banana" => 3, "apple" => 1];
$b = ["orange" => 1, "apple" => 4];

array_walk($c,"add",$b);

echo
"<pre>".print_r($c,true)."</pre>";
?>

This will output:

"orange" => 3,
"banana" => 3,
"apple" => 5

<< Back to user notes page

To Top