php json在数组中打印数组

时间:2014-06-22 17:37:53

标签: php json

我的json文件中有这个json项目

{
"results": [
{
    "title": "Brick Mansions",
    "released": "2014",
    "restricted": "12 \u00e1ra",
    "imdb": "6.0\/10  5,532 atkv.",
    "imdbLink": "http:\/\/www.imdb.com\/title\/tt1430612",
    "image": "http:\/\/kvikmyndir.is\/images\/poster\/9260_500.jpg",
    "showtimes": [
        {
            "theater": "Laugar\u00e1sb\u00ed\u00f3",
            "schedule": [
                "20:00",
                "22:00"
            ]
        }
    ]
}

我想用php打印戏剧和时间表。

我已经打印了其他所有内容。像这样......请记住$ movys是包含json内容的对象。

<?php foreach($movys->results as $movie): ?>
        <h2> <?php echo $movie->title; ?> </h2>
        <div class="posters"><img src="<?php echo $movie->image; ?>" alt="Plakat    fyrir <?php echo $movie->title; ?>"></div>              <ul>
            <li><p> <?php echo $movie->released; ?> </p></li>
            <li><p> <?php echo $movie->restricted; ?> </p></li>
            <li><p> <?php echo $movie->imdb; ?> </p></li>
            <li><p> <?php echo $movie->imdbLink; ?> </p></li>
        </ul>
    ??????  <?php foreach($movys->results{"showtimes"} as $hallo): ?>
??????          <h2><?php echo $hallo->theater; ?></h2>
??????      <?php endforeach; ?>

    <?php endforeach; ?>

1 个答案:

答案 0 :(得分:0)

<?php 
foreach($movie->showtimes as $showtimes)
{
    echo $showtimes->theater . ":\n";
    foreach ( showtimes->schedule as $schedule )
         echo "> " . $schedule . "\n";
}