theglobe Posted September 19, 2021 Share Posted September 19, 2021 There are still elements in the array with blank spaces. Not sure if i am missing something here <?php $ch= curl_init('https://coderbyte.com/api/challenges/json/json-cleaning'); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); $newdata = json_decode($data,true); foreach ($newdata as $key => $value) { if(is_array($value)) { foreach ($value as $about => $ddata) { if($ddata == "" || $ddata == 'N/A' || $ddata == '-' ) { unset($value[$about]); } } } else{ if($value == "" || $value == 'N/A' || $value == '-' ) { unset($newdata[$key]); } } } var_dump($newdata); curl_close($ch); ?> Quote Link to comment Share on other sites More sharing options...
benanamen Posted September 19, 2021 Share Posted September 19, 2021 (edited) Look at the result of $data. Edited September 19, 2021 by benanamen Quote Link to comment Share on other sites More sharing options...
theglobe Posted September 19, 2021 Author Share Posted September 19, 2021 i dont know what you mean. but thanks for the help Quote Link to comment Share on other sites More sharing options...
theglobe Posted September 19, 2021 Author Share Posted September 19, 2021 $data has the $key and key value pair, but i dont know how to access the [first], and [middle] Quote Link to comment Share on other sites More sharing options...
benanamen Posted September 19, 2021 Share Posted September 19, 2021 (edited) I mean dump the $data variable. There is nothing there to loop over. var_dump($data); Edited September 19, 2021 by benanamen Quote Link to comment Share on other sites More sharing options...
theglobe Posted September 19, 2021 Author Share Posted September 19, 2021 foreach ($newdata as $key => $value){ if(!is_array($value)){ if($value == " " || $value == 'N/A'){ unset($newdata[$key]); } }else { if($key == " " || $key == 'N/A'){ unset($newdata[$key]); } } } i changed and took ddata, now it deleted the [DOB] since it was NULL, but it didnt remove [middle] that is inside [name] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.