get_intent_sales( $current ); $total = array_sum( array_column( $rows, 'revenue' ) ); $data = array_map( function ( $row ) use ( $total ) { return array( 'intent' => $row['intent'], 'revenue' => $row['revenue'], 'orders' => $row['orders'], 'percentage' => $total > 0 ? round( $row['revenue'] / $total * 100, 2 ) : 0, ); }, $rows ); return array( 'current_period' => array( 'from' => $current['from'], 'to' => $current['to'] ), 'compare_period' => array( 'from' => $compare['from'], 'to' => $compare['to'] ), 'total_revenue' => round( $total, 2 ), 'data' => $data, ); } }