Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $data = [
- "PO1080|2018-10-21|2",
- "PO1080|2018-10-22|1",
- "PO1102|2018-10-21|1",
- "PO1080|2018-10-25|1",
- ];
- $res = [];
- foreach ($data as $v) {
- [$sales, $date, $total] = explode('|', $v);
- if (!isset($res[$sales])) {
- $res[$sales] = [
- "sales" => $sales,
- "tanggal" => [],
- "total" => [],
- ];
- }
- $res[$sales]["tanggal"][] = $date;
- $res[$sales]["total"][] = intval($total);
- }
- $result = array_values($res);
- echo (json_encode($result, JSON_PRETTY_PRINT));
Advertisement
Add Comment
Please, Sign In to add comment