How to sum numbers in arrays in php?

In php, how do I get the total number of posts (16)?

array1("posts" => 2, "reactions" => 0)

array2("posts" => 4, "reactions" => 4)

array3("posts" => 7, "reactions" => 0)

array4("posts" => 3, "reactions" => 1)


You can use this function array_merge_recursive And I made an example for you

$a = array("posts" => 2, "reactions" => 0);
$b = array("posts" => 4, "reactions" => 4);
$c = array("posts" => 7, "reactions" => 0);
$d = array("posts" => 3, "reactions" => 1);
$array = array_merge_recursive($a,$b,$c,$d); 
$sum = array_sum($array['posts']); 
echo $sum; 

If you want to read more about array_merge_recursive

Follow this Link

Need Your Help

Anyway to have Find method start at the very firs cell ie A1

excel vba

I have some really simple code that is looking for the first cell (Rng) to contain a certain string (FindString) cells in a range (A:A). Based on the data (which varies) sometimes this string is in...

Fancybox iframe working in compiler but not browser

jquery html fancybox

I'm having an issue with getting the fancybox iframe to load in the browser. I'm not sure what it is (I feel like it's something dumb) and I could use a hand.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.