错误:注意:尝试获取非对象

时间:2016-03-23 16:11:27

标签: php betfair

我有以下代码获取数据列表,我试图通过' name'来过滤这些数据。但是我收到了这个错误:

  

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

代码

 $bpl = 31;

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

$eventBetfair->withMarketFilter($marketFilter);

$bplevents = $eventBetfair->getResults();

print_r($bplevents->name);

数据/结果

以下结果是当我打印' $ bplevents'如下图所示:

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 ) )

2 个答案:

答案 0 :(得分:1)

输出是一个数组,没有对象。使用$ bplevents->名称,您将调用一个对象。 我会做$ bplevents ['name'],这是调用数组的正确方法。

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

foreach($bplevents as $amount => $array){
     print_r($array['event']['name']);
}

答案 1 :(得分:0)

$ bplevents传递数组而不是对象。调用该名称的正确方法如下。

print_r($bplevents[0]['element']['namne']);