Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- =======================================
- foreach ($period_a as $key => $value) {
- $result['data'][] = $period_a[$key];
- if ($period_b_start_date && $period_b_end_date) {
- $result['data'][] = $period_b[$key];
- if ($period_a[$key]['payment_type_id'] == $period_b[$key]['payment_type_id']) {
- $result['data'][$key]['sum_b'] = $period_b[$key]['sum'];
- $result['data'][$key]['total_b'] = $period_b[$key]['total'];
- }
- }
- }
- header('Content-Type: application/json');
- echo json_encode($result);
- =============== PERIOD A ===============
- {
- "data": [
- {
- "payment_type_id": 2,
- "description": "Χρεωστική Κάρτα",
- "sum": "12.50",
- "total": "12.50"
- }
- ]
- }
- =============== PERIOD B ===============
- {
- "data": [
- {
- "payment_type_id": 1,
- "description": "Μετρητά",
- "sum": "20.83",
- "total": "27.08"
- },
- {
- "payment_type_id": 2,
- "description": "Χρεωστική Κάρτα",
- "sum": "6.25",
- "total": "27.08"
- }
- ]
- }
- =============== TARGET ===============
- {
- "data": [
- {
- "payment_type_id": 1,
- "description": "Μετρητά",
- "sum": "20.83",
- "total": "27.08"
- },
- {
- "payment_type_id": 2,
- "description": "Χρεωστική Κάρτα",
- "sum": "12.50",
- "total": "12.50"
- "sum_b": "6.25",
- "total_b": "27.08"
- }
- ]
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement