I have this in my functions.php that creates a shopping cart widget with the plugin Marketpress.
<?php function marketpress_get_cart_subtotal($format_currency=true) {
global $mp;
$selected_cart = $mp->get_cart_contents(true);
if (!$selected_cart) return;
foreach ($selected_cart as $bid => $cart) {
if (is_multisite())
switch_to_blog($bid);
foreach ($cart as $product_id => $variations) {
foreach ($variations as $variation => $data) {
$totals[] = $mp->before_tax_price($data['price'], $product_id) * $data['quantity'];
}
}
//go back to original blog
if (is_multisite())
switch_to_blog($current_blog_id);
}
$total = array_sum($totals);
if ($total > 0)
return $mp->format_currency('', $total);
else
return '$0.00';
}
?>
This works fine locally on MAMP, but when I upload it to my server I get "Warning: array_sum() expects parameter 1 to be array, null given in functions.php on line 255" instead of the cart total.
What is wrong with the code, and why is there a discrepency between the same file on my localhost and the online server?

$totalsisnull, meaning it is not defined. Since$totalsgets set when$carthas data as$product_id => $variations, the problem is likely either that you have no$cartdefined, or$carthas no$variations. The solution is to wrap$totalin anif ( isset( $totals ) )conditional. – Chip Bennett Dec 12 '12 at 16:57