我從外部API提取電影數據以創建類似於IMDb的數據庫,用於我的最後一年大學項目,並且發佈日期信息格式爲YYYY-MM-DD (即2012年12月16日顯示爲2012-12-16,而不是16-12-2012)。有什麼方法可以重新排列陣列的片段以便爲英國英國觀衆重新排列它們?將美國格式的數組元素更改爲英國
的發佈日期如下,從TMDB API在getMovieReleases功能收集的原始結果(NB,以節省後期的大小,我只複製從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>
嗯,在你的原始數組的日期是在'YYYY-MM-DD'。你能明確指出**你在MM-DD-YYYY中的日期嗎? – zerkms
我的歉意,我弄糊塗了。我試圖將日期打印爲DD-MM-YYY,而不是YYYY-MM-DD!我現在編輯原文,以反映這一點。 –