gpt4 book ai didi

php - 在白天获取数组的特定部分

转载 作者:行者123 更新时间:2023-11-29 23:29:15 25 4
gpt4 key购买 nike

我有一组 YouTube 视频,我想要一个特定的白天视频。

Array
(

[10] => Array
(
[video_id] => 2
[show_date] => 2014-11-01
[show_time] => 14:40:00
[video_duration] => 5470
[video_youtube_id] => MTLObnglz_U
[video_title] => Out Of Bounds (OV)
[source] => channel: netzkino
)

[11] => Array
(
[video_id] => 155
[show_date] => 2014-11-01
[show_time] => 21:10:00
[video_duration] => 9392
[video_youtube_id] => OO-e8_-bMv8
[video_title] => Foo Fighters Live at Lollapalooza Brazil 2012 Full Concert HD 720p
[source] =>
)

[14] => Array
(
[video_id] => 3
[show_date] => 2014-11-01
[show_time] => 23:59:00
[video_duration] => 5520
[video_youtube_id] => cf7Eu9WJ_ek
[video_title] => City of Sex (Komödie mit Nicole Kidman)
[source] =>
)

)

所以当它在“2014-11-01 21:10:00”和(+video_duration)“2014-11-01 23:46:31”之间时,我想得到“Foo Fighters”:

[11] => Array
(
[video_id] => 155
[show_date] => 2014-11-01
[show_time] => 21:10:00
[video_duration] => 9392
[video_youtube_id] => OO-e8_-bMv8
[video_title] => Foo Fighters Live at Lollapalooza Brazil 2012 Full Concert HD 720p
[source] =>
)

最佳答案

最简单的方法是在数组上使用 foreach() 并检查每条记录。像这样的事情:

$array = array(...); // Your array
$newArray = array();
$currentTime = time();

foreach ($array as $key => $value) {

$fromTime = strtotime($value['show_date'] . ' ' . $value['show_time']);
$toTime = $fromTime + $value['video_duration'];

if ($fromTime <= $currentTime && $toTime >= $currentTime) {
$newArray[] = $value;
}
}

关于php - 在白天获取数组的特定部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26693746/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com