1

I got this problem. I am trying to get certain objects within an array from an object.

I made this function where I ask a single match to display.

function match () {

    $Match = WaterpoloAPI::call("Matches", "getMatch", Array($_GET["MatchId"]));
    echo "<td>$Match->Date</td> <td>$Match->Time</td> <td>$Match->PoolName</td><td class='text-center'>$Match->HomeTeam </td><td><strong><a href='wedstrijd?MatchId=".$Match->Id."'>$Match->ResultHome - $Match->ResultGuest </a></strong></td><td> $Match->AwayTeam</td>";
}

I can choose a list of items from that match to show...

MatchItem

Properties

Name    Type
Id  string
MatchNumber int
Date    string
Time    string
DepartmentId    string
DepartmentCode  string
DepartmentName  string
HomeTeamId  string
HomeTeam    string
AwayTeamId  string
AwayTeam    string
PoolId  string
PoolName    string
PoolCity    string
MatchReport string
Played  boolean
ResultHome  int
ResultGuest int
**Referees  MatchRefereeItem[]**

but I want to show referees ...but it is in an array...how do I do that?

**MatchRefereeItem
Properties**

Name    Type
Id  string
Initials    string
FirstName   string
Insertion   string
LastName    string
Sex string
Indication  int

I am still learning and maybe it's a silly question, therefore I am sorry. but it would be great if someone could help me.

u_mulder
  • 54,101
  • 5
  • 48
  • 64
  • 1
    try https://stackoverflow.com/questions/4414623/loop-through-an-array-php – mim. Jul 14 '17 at 09:44
  • u_mulder thx for your answer, but it still not working ...I tried this foreach($Referees as $Referee) { echo "$Referee->FirstName"; } – Donny Abraham Jul 14 '17 at 10:05

2 Answers2

0

MatchItem class should have a method like getRefereeItems that returns the array of Referees. Or the properties are public.

Then you can make something like this:

$referees = [];
foreach($match->Referees as $refereeItem) {
    $referees[] = $refereeItem->FirstName . ' ' . $refereeItem->LastName;
}

echo implode(', ', $referees);
fabpico
  • 2,628
  • 4
  • 26
  • 43
  • Thx Fabian, so I tried your code like this $Referees = []; foreach($Match->getReferees() as $RefereeItem) { $Referees[] = $RefereeItem->FirstName(); echo implode(', ', $Referees); } Still it's not working ....what am I doing wrong? – Donny Abraham Jul 14 '17 at 10:31
  • Do you receive any error messages? Did you check your error reporting that its set to E_ALL? Otherwise try to var_dump($Match); and post me the real structure of those referees so i can help better. – fabpico Jul 18 '17 at 07:45
  • it doesn't show anything... the structure can be seen at http://test.waterpolo-online.com/service/ ..option matches ....I want to show the referees that are linked to the match – Donny Abraham Jul 18 '17 at 15:53
  • I need more information. Are the properties private or public? What methods does the $match have? See example https://3v4l.org/RtOjS. – fabpico Jul 19 '17 at 09:43
0

Fabian when I do a var_dump($Match) it shows me the data's of each object

object(stdClass)#4911 (19) {
 ["Id"]=> string(15) "WW0000000001837" 
 ["MatchNumber"]=> int(890)
 ["Date"]=> string(10) "16-12-2016"
 ["Time"]=> string(5) "20:30" 
 ["DepartmentId"]=> string(15) "WW0000000000085"
 ["DepartmentCode"]=> string(5) "BC SD"
 ["DepartmentName"]=> string(17) "Beker/Coupe Dames"
 ["HomeTeamId"]=> string(15) "WW0000000000574"
 ["HomeTeam"]=> string(9) "Eeklo MZV"
 ["AwayTeamId"]=> string(15) "WW0000000000570" 
 ["AwayTeam"]=> string(17) "Leuven Aqua LAQUA"
 ["PoolId"]=> string(15) "WW0000000000024" 
 ["PoolName"]=> string(18) "Stedelijk Zwembad "
 ["PoolCity"]=> string(5) "Eeklo" 
 ["MatchReport"]=> string(2) "NO" 
 ["Played"]=> bool(true) 
 ["ResultHome"]=> int(18) 
 ["ResultGuest"]=> int(4)
 ["Referees"]=> array(2) {
    [0]=> object(stdClass)#4907 (7) {
            ["Id"]=> string(15) "WW0000000000052"
            ["Initials"]=> string(0) "" 
            ["FirstName"]=> string(7) "Niculae" 
            ["Insertion"]=> string(0) "" 
            ["LastName"]=> string(8) "Fulgeanu"
            ["Sex"]=> string(1) "M"
            ["Indication"]=> int(1)
        } 
        [1]=> object(stdClass)#4865 (7) { 
            ["Id"]=> string(15) "WW0000000000054"
            ["Initials"]=> string(0) "" 
            ["FirstName"]=> string(6) "Wouter" 
            ["Insertion"]=> string(0) ""
            ["LastName"]=> string(8) "Fontaine"
            ["Sex"]=> string(1) "M" 
            ["Indication"]=> int(2) } 
        } 
 }
fabpico
  • 2,628
  • 4
  • 26
  • 43
  • Ok it seems that you can access the properties as public. See i editet my code example https://stackoverflow.com/questions/45099649/how-to-ask-certain-objects-within-a-array-within-an-object?answertab=active#tab-top – fabpico Jul 19 '17 at 09:47
  • 1
    Thx Fabian you made my day...it worked..I am so happy :D – Donny Abraham Jul 19 '17 at 10:03