$task = array(
"Monday" => array("10:11","12:00","23:18"),
"Tuesday" => array("08:00"),
"Wednesday" => array("10:00","11:30"),
"Thursday" => array("11:00"),
"Friday" => array("08:00","11:30","23:18"),
"Saturday" => array("08:00"),
"Sunday" => array("09:00","14:30"),
);
$post = array("post 1","post 2","post 3","post 4","post 5","post 6","post 7","post 8","post 9","post 10","post 11","post 12","post 13","post 14","post 15","post 16");
$arr = array();
$i = 0;
foreach($task as $k => $t){
foreach($t as $tas){
$arr[$i++] = array($k, $tas);
}
}
$total = $i - 1;
$i = 0;
date_default_timezone_set("Asia/Ho_Chi_Minh");
$time_today = date("H:i");
$date = date("Y-m-d");
$dateweek_today = date("l");
$flag = "";
foreach($post as $val){
if($i > $total)
$i = 0;
$post = ucfirst($val);
$day_post = ucfirst($arr[$i][0]);
$time_post = $arr[$i][1];
if($day_post == $dateweek_today){
echo $post.": ".$day_post." at ".$time_post." | ".$date."<br />";
$flag = "ok";
}else{
if($flag == "ok"){
$date = date('Y-m-d', strtotime('+1 day', strtotime($date)));
echo $post.": ".$day_post." at ".$time_post." | ".$date."<br />";
}else{
}
}
if($flag == "ok"){
$dateweek_today = $day_post;
}
$i++;
}
您好, 我已经尝试使用当前时间在数组中安排我的帖子,但我在第1帖子到第4帖后输了。结果是:
Post 5: Wednesday at 10:00 | 2016-06-01
Post 6: Wednesday at 11:30 | 2016-06-01
Post 7: Thursday at 11:00 | 2016-06-02
Post 8: Friday at 08:00 | 2016-06-03
Post 9: Friday at 11:30 | 2016-06-03
Post 10: Friday at 23:18 | 2016-06-03
Post 11: Saturday at 08:00 | 2016-06-04
Post 12: Sunday at 09:00 | 2016-06-05
Post 13: Sunday at 14:30 | 2016-06-05
Post 14: Monday at 10:11 | 2016-06-06
Post 15: Monday at 12:00 | 2016-06-06
Post 16: Monday at 23:18 | 2016-06-06
希望任何人都可以帮我这个代码。我想安排我的帖子1发布到16,并从当前时间开始,例如:
Post 1: Wednesday at 10:00 | 2016-06-01
Post 2: Wednesday at 11:30 | 2016-06-01
Post 3: Thursday at 11:00 | 2016-06-02
Post 4: Friday at 08:00 | 2016-06-03
Post 5: Friday at 11:30 | 2016-06-03
Post 6: Friday at 23:18 | 2016-06-03
Post 7: Saturday at 08:00 | 2016-06-04
Post 8: Sunday at 09:00 | 2016-06-05
Post 9: Sunday at 14:30 | 2016-06-05
Post 10: Monday at 10:11 | 2016-06-06
Post 11: Monday at 12:00 | 2016-06-06
Post 12: Monday at 23:18 | 2016-06-06
.................
答案 0 :(得分:0)
使用它可能对你有用。
<?php
$task = array(
"Monday" => array("10:11","12:00","23:18"),
"Tuesday" => array("08:00"),
"Wednesday" => array("10:00","11:30"),
"Thursday" => array("11:00"),
"Friday" => array("08:00","11:30","23:18"),
"Saturday" => array("08:00"),
"Sunday" => array("09:00","14:30"),
);
$post = array("post 1","post 2","post 3","post 4","post 5","post 6","post 7","post 8","post 9","post 10","post 11","post 12","post 13","post 14","post 15","post 16");
$arr = array();
$i = 0;
foreach($task as $k => $t){
foreach($t as $tas){
$arr[$i++] = array($k, $tas);
}
}
$total = $i - 1;
$i = 0;
date_default_timezone_set("Asia/Ho_Chi_Minh");
$time_today = date("h:i");
$date = date("Y-m-d");
$dateweek_today = date("l");
$flag = "";
foreach($post as $val){
if($i > $total)
$i = 0;
$post = ucfirst($val);
$day_post = ucfirst($arr[$i][0]);
$time_post = $arr[$i][1];
if($i==0) $time_post= $time_today;
if($day_post == $dateweek_today){
echo $post.": ".$day_post." at ".$time_post." | ".$date."<br />";
$flag = "ok";
}else{
$date = date('Y-m-d', strtotime('+1 day', strtotime($date)));
echo $post.": ".$day_post." at ".$time_post." | ".$date."<br />";
}
if($flag == "ok"){
$dateweek_today = $day_post;
}
$i++;
}
答案 1 :(得分:0)
UPDATE 我试图保存我的任务不显示。
$task = array(
"Monday" => array("10:11","12:00","23:18"),
"Tuesday" => array("08:00"),
"Wednesday" => array("10:00","11:30"),
"Thursday" => array("11:00"),
"Friday" => array("08:00","11:30","23:18"),
"Saturday" => array("08:00"),
"Sunday" => array("09:00","14:30"),
);
$post = array("post 1","post 2","post 3","post 4","post 5","post 6","post 7","post 8","post 9","post 10","post 11","post 12","post 13","post 14","post 15","post 16");
$arr = array();
$i = 0;
foreach($task as $k => $t){
foreach($t as $tas){
$arr[$i++] = array($k, $tas);
}
}
$total = $i - 1;
$i = 0;
date_default_timezone_set("Asia/Ho_Chi_Minh");
$time_today = date("H:i");
$date = date("Y-m-d");
$dateweek_today = date("l");
$flag = "";
foreach($post as $val){
if($i > $total)
$i = 0;
$post = ucfirst($val);
$day_post = ucfirst($arr[$i][0]);
$time_post = $arr[$i][1];
if($day_post == $dateweek_today){
echo $post.": ".$day_post." at ".$time_post." | ".$date."<br />";
$flag = "ok";
}else{
if($flag == "ok"){
$date = date('Y-m-d', strtotime('+1 day', strtotime($date)));
echo $post.": ".$day_post." at ".$time_post." | ".$date."<br />";
}else{
$save_task[] = array(
"post" => $post,
"day_post" => $day_post,
"time" => $time_post,
"date" => $date
);
}
}
if($flag == "ok"){
$dateweek_today = $day_post;
}
$i++;
}
echo "<pre>";
print_r($save_task);
echo "</pre>";
}
结果:
Post 5: Wednesday at 10:00 | 2016-06-01
Post 6: Wednesday at 11:30 | 2016-06-01
Post 7: Thursday at 11:00 | 2016-06-02
Post 8: Friday at 08:00 | 2016-06-03
Post 9: Friday at 11:30 | 2016-06-03
Post 10: Friday at 23:18 | 2016-06-03
Post 11: Saturday at 08:00 | 2016-06-04
Post 12: Sunday at 09:00 | 2016-06-05
Post 13: Sunday at 14:30 | 2016-06-05
Post 14: Monday at 10:11 | 2016-06-06
Post 15: Monday at 12:00 | 2016-06-06
Post 16: Monday at 23:18 | 2016-06-06
Array
(
[0] => Array
(
[post] => Post 1
[day_post] => Monday
[time] => 10:11
[date] => 2016-06-01
)
[1] => Array
(
[post] => Post 2
[day_post] => Monday
[time] => 12:00
[date] => 2016-06-01
)
[2] => Array
(
[post] => Post 3
[day_post] => Monday
[time] => 23:18
[date] => 2016-06-01
)
[3] => Array
(
[post] => Post 4
[day_post] => Tuesday
[time] => 08:00
[date] => 2016-06-01
)
)
我有4个帖子未显示,因为当$ flag ==“ok”时它无效。如何使用这4个帖子继续我的任务?