1

我有以下获取数据列表的代码,我正在尝试按“名称”过滤此数据,但出现此错误:

错误:注意:试图获取非对象的属性

代码

 $bpl = 31;

$marketFilter = MarketFilter::create()
    ->setCompetitionIds(array($bpl));

$eventBetfair->withMarketFilter($marketFilter);

$bplevents = $eventBetfair->getResults();

print_r($bplevents->name);

数据/结果

以下结果是我打印 '$bpevents' 时的结果,如下所示:

print_r($bplevents);

输出:

Array ( [0] => Array ( [event] => Array ( [id] => 27732436 [name] => Leicester v Southampton [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-03T12:30:00.000Z ) [marketCount] => 13 ) [1] => Array ( [event] => Array ( [id] => 2022802 [name] => Barclays Premier League [countryCode] => GB [timezone] => Europe/London [openDate] => 2015-11-21T12:45:00.000Z ) [marketCount] => 23 ) [2] => Array ( [event] => Array ( [id] => 27732438 [name] => Liverpool v Tottenham [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T16:30:00.000Z ) [marketCount] => 13 ) [3] => Array ( [event] => Array ( [id] => 27732439 [name] => Man Utd v Everton [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-03T15:00:00.000Z ) [marketCount] => 13 ) [4] => Array ( [event] => Array ( [id] => 5767793 [name] => Season Match Bets [countryCode] => GB [timezone] => Europe/London [openDate] => 2015-08-16T12:30:00.000Z ) [marketCount] => 17 ) [5] => Array ( [event] => Array ( [id] => 19478157 [name] => Head to Head Leagues [countryCode] => GB [timezone] => Europe/London [openDate] => 2015-08-16T12:30:00.000Z ) [marketCount] => 2 ) [6] => Array ( [event] => Array ( [id] => 27732449 [name] => Arsenal v Watford [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T14:00:00.000Z ) [marketCount] => 14 ) [7] => Array ( [event] => Array ( [id] => 27732434 [name] => Aston Villa v Chelsea [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T11:45:00.000Z ) [marketCount] => 12 ) [8] => Array ( [event] => Array ( [id] => 27732448 [name] => Bournemouth v Man City [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T14:00:00.000Z ) [marketCount] => 13 ) [9] => Array ( [event] => Array ( [id] => 27732444 [name] => Norwich v Newcastle [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T14:00:00.000Z ) [marketCount] => 13 ) [10] => Array ( [event] => Array ( [id] => 27732446 [name] => Sunderland v West Brom [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T14:00:00.000Z ) [marketCount] => 13 ) [11] => Array ( [event] => Array ( [id] => 27732447 [name] => West Ham v C Palace [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T14:00:00.000Z ) [marketCount] => 13 ) [12] => Array ( [event] => Array ( [id] => 27732443 [name] => Stoke v Swansea [countryCode] => GB [timezone] => Europe/London [openDate] => 2016-04-02T14:00:00.000Z ) [marketCount] => 13 ) )
4

2 回答 2

2

输出是一个数组,不是一个对象。使用 $bpevents->name 您正在调用一个对象。我会做 $bpevents['name'],这是调用数组的正确方法。

编辑:请检查您的输出。您的输出告诉您出了什么问题。你有一个多维数组。也许,在美化你的输出之后,我意识到你应该访问这个: $bplevents[0]['event']['name']..你也可以

foreach($bplevents as $amount => $array){
     print_r($array['event']['name']);
}
于 2016-03-23T16:33:17.130 回答
0

$bpevents 传递的是数组而不是对象。正确的称呼方式如下。

print_r($bplevents[0]['element']['namne']);
于 2016-03-23T16:17:22.327 回答