curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false); // curl_setopt($ch, CURLOPT_POSTFIELDS, '{"sport":"football","outcomeId":"155666431"}'); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, array('AppId: ' . $this->appId, 'Authorization: 8fa8f25310b05400938cc84ae5353ce2871882b02b236e929fab84fc73c4413e')); // Execute $result = curl_exec($ch); curl_close($ch); //return a asociative array return json_decode($result, true); } public function doSomethingWithThat() { $json = $this->curlMagic(); if (is_array($json)) { $array = array(); foreach ($json['tips'] as $tip) { $array[] = $tip['sport']; $array[$tip['sport']] = $tip['vc_outcome_id']; } $output = $array; } else { $output = 'We don\'t keep data for this source.'; } return $output; return $json; } } $call = new CallForTips(); echo '<pre>'; print_r($call->curlMagic()); echo '</pre>';