php - How to pull each game value if main value if true JSON in PHP
问题描述
PHP File for getting json value
$url = 'demo.json'; // path to your JSON file
$data = file_get_contents($url); // put the contents of the file into a variable
$characters = json_decode($data, true); // decode the JSON feed
<table>
<tbody>
<tr>
<th>id</th>
</tr>
<?php foreach ($characters['events'][0]['offers'][0]['outcomes'] as $character) : ?>
<tr>
<td> <?php echo $character['id']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Thank you for the solutions. only need to show data if main value is true from each game. Thanks Dhamo
解决方案
在 for 循环中检查主要条件
<?php
foreach ($characters['events'] as $events){
foreach ($events['offers'] as $offers){
if($offers['main']==true || $offers['main']==1){
foreach ($offers['outcomes'] as $character) : ?>
<tr>
<td> <?php echo $character['id']; ?></td>
<td> <?php echo $character['label']; ?></td>
<td> <?php echo $character['line']; ?></td>
<td> <?php echo $character['oddsAmerican']; ?></td>
<td> <?php echo $character['participant']; ?></td>
</tr>
<?php endforeach;
}
}
}?>
推荐阅读
- snowflake-cloud-data-platform - Snowflake 中 AccountAdmin 和 SysAdmin 的开箱即用授权是什么?
- ruby-on-rails - 已弃用 `Bundler.with_clean_env` 已弃用,取而代之的是 `Bundler.with_unbundled_env`
- python - Python 3 无法读取我的 .txt 文件。我该如何解决?
- c - RTOS TCB 与任务堆栈
- mongodb - Mongo 聚合与 Java 的循环和性能
- alias - ZSH 在 .zshrc 之外添加别名
- wordpress - $wpdb 删除语句无法正常工作
- php - Cron 在 Codeigniter PHP 中不能使用 post 方法
- python - x 轴标签未显示在 matplotlib 图中
- holoviews - 访问 holoviews Gridspace 的子图元素