0

我正在从外部 API 中提取电影数据,为我的最后一年大学项目创建一个类似于 IMDb 的数据库,并且发布日期信息的格式为YYYY-MM-DD(即 2012 年 12 月 16 日显示为 2012-12-16 ,而不是 2012 年 16 月 12 日)。有没有办法对数组的各个部分重新排序,以便为英国英语观众重新洗牌?

发布日期的原始结果如下,从 TMDb API 中的 getMovieReleases 函数收集(注意,为了节省帖子大小,我只复制了 getMovieReleases 函数的前 10 个结果):

[id] => 17578
    [countries] => Array
        (
            [0] => Array
                (
                    [iso_3166_1] => US
                    [certification] => PG
                    [release_date] => 2011-12-21
                )

            [1] => Array
                (
                    [iso_3166_1] => DE
                    [certification] => 6
                    [release_date] => 2011-10-27
                )

            [2] => Array
                (
                    [iso_3166_1] => FR
                    [certification] => 
                    [release_date] => 2011-10-26
                )

            [3] => Array
                (
                    [iso_3166_1] => TR
                    [certification] => 
                    [release_date] => 2011-11-04
                )

            [4] => Array
                (
                    [iso_3166_1] => DK
                    [certification] => 7
                    [release_date] => 2011-10-27
                )

            [5] => Array
                (
                    [iso_3166_1] => GB
                    [certification] => PG
                    [release_date] => 2011-10-26
                )

            [6] => Array
                (
                    [iso_3166_1] => FI
                    [certification] => 12
                    [release_date] => 2011-11-04
                )

            [7] => Array
                (
                    [iso_3166_1] => IT
                    [certification] => T
                    [release_date] => 2011-10-28
                )

            [8] => Array
                (
                    [iso_3166_1] => SE
                    [certification] => 
                    [release_date] => 2011-10-28
                )

            [9] => Array
                (
                    [iso_3166_1] => NL
                    [certification] => 6
                    [release_date] => 2011-10-26
                )

            [10] => Array
                (
                    [iso_3166_1] => BE
                    [certification] => 
                    [release_date] => 2011-10-26
                )
        )

)

我在我的 PHP 和 HTML 中调用数据如下,只选择美国和英国的发布日期:

$releases = $tmdb->getMovieReleases($tmdb_id);

$uk = $releases['countries']['14']['release_date'];
$us = $releases['countries']['0']['release_date'];

<section>
    <p class="title">RELEASE DATE</p>
    <p class="section_body">
        <?php echo $uk; ?> (UK)<br>
        <?php echo $us; ?> (US)
    </p>
</section>
4

2 回答 2

2

你想这样格式化日期吗?

<?php
        $source = '2011-11-04';
    $date = new DateTime($source);
    echo $date->format('d.m.Y')."<br/>"; // 04.11.2012
    echo $date->format('d-m-Y')."<br/>"; // 04-11-2011
?>
于 2012-12-16T13:08:09.990 回答
2
$uk = date('d/m/Y', strtotime($releases['countries']['14']['release_date']));

那应该为您指明正确的方向..

date()strtotime()

于 2012-12-16T13:09:10.723 回答