cyberfly
8/15/2017 - 4:33 AM

PHP array to JSON string for excel

PHP array to JSON string for excel

[
                            
                            
                                {
                                    "response": "",
                                        "question": "How did you rate the quality of the services offered to you?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How would you rate the accessibility of information?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How helpful were our representatives in their assistance?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How responsive were our representatives?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How easy was it for you to reach our representatives?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How competent were our representatives?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How would you rate the professionalism displayed by our representatives in their handling of enquiries and complaints?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "Overall were you satisfied with the services that we offered?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "If your respond is below 3 for Question 8, please explain why?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How did you hear about MSC Malaysia Status?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "How do you think the services offered to you can be further improve?",
                                        
                                    },
                                    
                                {
                                    "response": "",
                                        "question": "Any other comments or suggestions?",
                                        
                                    },
                                    
                            ]
$data_company_csi = $profile["data_company_csi"];

                        if (isset($data_company_csi) && is_array($data_company_csi)) {

                            $csi_result = '[
                            
                            ';

                            foreach ($data_company_csi as $row) {

                                $csi_result = $csi_result. '
                                {
                                    ';

                                foreach($row as $key => $val)
                                {
                                    if ($key === 'question' || $key === 'response' ) {
                                        $csi_result = $csi_result. '"'.$key.'": "'.$val.'",
                                        ';
                                    }
                                }

                                $csi_result = rtrim($csi_result, ',');

                                $csi_result = $csi_result. '
                                    },
                                    ';

                            }

                            $csi_result = $csi_result. '
                            ]
                            ';
                        }