salin kunwar
salin kunwar

Reputation: 1188

How to solve usage of anonymous function below 5.3 php version?

$total_amount=array_sum(array_map(function($item) { 
                            return $item['total_price']; 
                        }, $cartsItems));

This is my code which returns a total price in cart. I have installed a higher version on my local but the server is 5.2. How can I solve this problem?

Upvotes: 0

Views: 33

Answers (1)

Niroj Adhikary
Niroj Adhikary

Reputation: 1835

function total_sum_of_cart($item){
    return $item['total_price'];
}
$total_amount=array_sum(array_map('total_sum_of_cart',$cartsItems));

Upvotes: 2

Related Questions