I have a multidimensional array with a race type column and a boats column (which has the total number of boats for each race type). This is how I am getting the array values:
$boats = $wpdb->get_results("
select rt.race_type
,sum(tr.boat_count) boats
from registrations tr
group by rt.race_type;
");
The array works perfectly fine. But now I am trying to get the total number of boats for all race types (without using a loop). After some research, I have tried the code below, but it doesn't seem to be working:
$totalboats = array_sum(array_column($boats,'boats'));
When I run the following command:
echo $totalboats;
The result of that is 0, which is clearly wrong.
Any ideas? I am running PHP 5.6.29.
================== EDIT 01 ==================
As requested, here is the var_dump of $boats:
array(2) {
[0]=>
object(stdClass)#672 (2) {
["race_type"]=> string(12) "Elite 8-Hour"
["boats"]=> string(1) "2"
}
[1]=>
object(stdClass)#673 (2) {
["race_type"]=> string(12) "Sport 4-Hour"
["boats"]=> string(1) "2"
}
}
var_dump($boats);?sum(tr.boat_count) AS boats, notsum(tr.boat_count) boats.$wpdb->get_results- it appears this method may actually hydrate into objects as opposed to a multidimensional array. codex.wordpress.org/Class_Reference/wpdbASkeyword.