I am trying to get data through an API (bet365) it returns this data in JSON, I have created a function to extract this data and transform into array
The following function: public function api_footer () {
$url = "https://api.betsapi.com/v1/bet365/inplay_filter?sport_id=1&token=token&LNG_ID=22" . $this->refcode;
$request_headers = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $request_headers);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
if (curl_errno($ch))
{
print "Error: " . curl_error($ch);
}
else
{
// Show me the result
$transaction = json_decode($data, TRUE);
curl_close($ch);
//var_dump($transaction);
$dados = array();
$dados['transaction'] = $transaction;
}
$this->load->view('header');
$this->load->view('home', $dados);
$this->load->view('footer');
}
JSON template I'm working on:
{
"success": 1,
"pager": {
"page": 1,
"per_page": 1000,
"total": 4
},
"results": [
{
"id": "77564080",
"time": "1543528800",
"time_status": "1",
"league": {
"id": "3024",
"name": "Copa Libertadores - Feminino"
},
"home": {
"id": "9105",
"name": "EC Iranduba - Feminino"
},
"away": {
"id": "170148",
"name": "Atlético Huila - Feminino"
},
"ss": "1-0",
"our_event_id": "1093051"
},
I'm showing the data in the view as follows:
echo ($transaction['results'][0]['league']['name']);
echo ($transaction['results'][0]['ss']);
I need to get this data without indicating the Index, I have tried the following ways:
foreach ($transaction as $row){
echo $row->name;
}
//ou
foreach ($transaction as $row){
echo $row->results['name'];
}
// ou
foreach ($transaction as $row){
echo $row->results['league']['name'];
}
Note: I want without the index because I do not want to put the games manually that is automatically placed, for example: I have 10 games in the afternoon the way I'm doing I have to put 10 indexes but the night might have only 2 for example .