0

I am trying to store every competition id in the following function:

function getSoccerByCountry($appKey, $sessionToken, $country, $competitionid)
{
    $jsonResponse = sportsApingRequest($appKey, $sessionToken, 'listMarketCatalogue', '{"filter":{
                "eventTypeIds": [
                    "1"
                ],"competitionIds":["' . $competitionid . '"],"marketTypeCodes":["MATCH_ODDS"],"marketCountries":["' . $country . '"],"inPlayOnly": true
            },
            "maxResults": "200",
            "marketProjection": [
                "COMPETITION",
                "EVENT",
                "EVENT_TYPE",
                "RUNNER_DESCRIPTION",
                "RUNNER_METADATA",
                "MARKET_START_TIME"
            ]
        },
        "id": 1}
]');

I have created this for each loop which loops every key value of the array and gets only the competition id which is being passed to the getSoccerByCountry function.

foreach ($getSoccerComp as $key1)
{           
    $getSoccerCountry = getSoccerByCountry($appKey, $sessionToken, $countrycode, $key1->competition->id);
}

Although, all the competition ids are passing as a whole integer, I want them to pass separated with a comma.

Screenshot

Fombe F
  • 15
  • 1
  • 9
  • 2
    That code doesn't look right. You're just overwriting `$getSoccerCountry` each time in your loop. Is that your real code? – Here2Help Mar 01 '16 at 20:49
  • 1
    there are no arrays in your code... – Marc B Mar 01 '16 at 20:51
  • 2
    you don't show what you are echoing – Pitchinnate Mar 01 '16 at 20:51
  • According to your updated code, `$getSoccerCountry = getSoccerByCountry` is obselete since `getSoccerByCountry()` does not return anything. And still I don't see an echo that would display the things on the screenshot. – Xorifelse Mar 01 '16 at 21:20
  • I don't want them to display, I want to pass each value separated with a comma, I printed out the array from the screenshot so you guys can understand – Fombe F Mar 01 '16 at 21:21
  • The problem is, it is harder for us to read 1 thing and seeing the other. You state that you only echo the array so we could understand. But I can only assume you printed out the result of `$key1->competition->id` and since its in a loop it could explain the long list of integers. This could be miss communication all together. Don't change the code and show a different output as it is important for us to know where the output occurred and what variable held the value. – Xorifelse Mar 01 '16 at 21:45
  • Yes I printed out $key->competition->id to understand the problem. Then I realised that the getSoccerByCountry is not returning any sports events since the $competitionid is a whole integer value and not separated with commas (means that there more than one competition id) – Fombe F Mar 01 '16 at 21:54

1 Answers1

0

Something like this?

foreach ($getSoccerComp as $key1){           
    $ids[] = $key1->competition->id;
}

getSoccerByCountry($appKey, $sessionToken, $countrycode, implode(',', $ids));

Sinse you weren't doing anything with $getSoccerCountry except rewriting the variable over and over again with value null I removed the obselete code.

Xorifelse
  • 7,878
  • 1
  • 27
  • 38
  • It's being outputted but for testing reasons, I want to enter each competition id in the function getSoccerByCountry with a comma and not a whole integer value – Fombe F Mar 01 '16 at 21:12
  • No, that displayed Array, Array, Array. I want to pass each competition id separated with commas to the getSoccerByCountry function and not display them – Fombe F Mar 01 '16 at 21:32
  • Did the re-updated code work for you or did you add-in some extra changes? – Xorifelse Mar 01 '16 at 22:09
  • I think so, but now I need to store 'getSoccerByCountry' to a variable so I can loop again and display every event name, event data and competition regarding to the particular id, but when I do the following: $getSoccer = getSoccerByCountry($appKey, $sessionToken, $countrycode, $id); And print the '$getSoccer', I get an empty Array() – Fombe F Mar 01 '16 at 22:58
  • It also returns this error: Fatal error: Function name must be a string in – Fombe F Mar 02 '16 at 10:47