0 レビュー
2 回答
php-オブジェクト内の配列内の特定のオブジェクトに質問する方法
この問題が発生しました。オブジェクトから配列内の特定のオブジェクトを取得しようとしています。
この関数は、1つの一致を表示するように要求する機能を作成しました。
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>";
}
その一致から表示するアイテムのリストを選択できます...
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[]**
しかし、レフリーを見せたいのですが...それは配列になっています...どうすればいいですか?
**MatchRefereeItem
Properties**
Name Type
Id string
Initials string
FirstName string
Insertion string
LastName string
Sex string
Indication int
私はまだ学んでいて、おそらくそれはばかげた質問なので、申し訳ありません。でも誰かが私を助けてくれたら素晴らしいと思います。
わからない
0
レビュー
答え :
解決策:
MatchItem
クラスには、審判の配列を返す getRefereeItems
のようなメソッドが必要です。 。または、プロパティは公開されています。
次に、次のようなものを作成できます:
$referees = [];
foreach($match->Referees as $refereeItem) {
$referees[] = $refereeItem->FirstName . ' ' . $refereeItem->LastName;
}
echo implode(', ', $referees);
わからない
0
レビュー
答え :
解決策:
var_dump($Match)
を実行すると、各オブジェクトのデータが表示されます
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) }
}
}
わからない
同様の質問
私たちのウェブサイトで同様の質問で答えを見つけてください。