[英]read laravel object and get data
我正在嘗試讀取 laravel 對象並將其分配給一個新變量我不知道這樣做請有人幫忙
這是我的職責
public function nextToJumpGrs(CompetitionService $competitionService, CachedEventResourceService $cachedEventResourceService, ConfigurationRepositoryInterface $configurationRepository,MarketRepository $marketTypeRepository)
{
$nextToJump = $cachedEventResourceService->nextToJump();
$markets=array();
$config = $configurationRepository->getConfigByName('sports_settings', true);
$competitions = $competitionService->getCompetitionsByN2JEventResourcesGrs($nextToJump->slice(0, array_get($config, 'next_to_jump_events')));
return $competitions;
}
}
這就是 $competitions 的回報
我想閱讀那些市場 [] 和產品 [] 並分配給另一個變量,請有人幫忙
只是排版它
$array = (array) $competitions;
然后循環遍歷它
$markets = [];
$products = [];
foreach($array as $item) {
dump($item['id']);
dump($item['name']);
//...
foreach($item['events'] as $event) {
dump($event['id']);
dump($event['name']);
//...
$markets[$item['id']][] = $event['markets'];
foreach($event['markets'] as $market) {
dump($market['id']);
dump($market['name']);
dump($market['line']);
//...
}
$products[$item['id']][] = $event['products'];
foreach($event['products'] as $product) {
dump($product['product_id']);
dump($product['bet_type']);
dump($product['product_code']);
//...
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.