如何在php中创建一个星期名称数组 [英] how to create array of a week days name in php

查看:59
本文介绍了如何在php中创建一个星期名称数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这很愚蠢,但是我该怎么做? 我想通过PHP创建一个7天的数组 我的意思是所有七个工作日. 我不想像他那样写它们:

I know this is stupid, but how would I do this? I would like to create an array of seven days through PHP What I mean is all the seven weekdays. I don't want to write them like his:

sunday monday tuesday ...etc

几天将从星期日开始,这意味着如果今天是3月29日(星期一),那么它将自动获取当前日期并创建一个从星期日开始的工作日数组.

and days will be starting from sunday which means if today is the 29th of march (monday) then it automatically grabs the current date and create an array of weekdays starting from Sunday.

数组始终采用这种方式

 $weakarray=("sunday","monday",......,"saturday");

推荐答案

这可能有效..

$timestamp = strtotime('next Sunday');
$days = array();
for ($i = 0; $i < 7; $i++) {
    $days[] = strftime('%A', $timestamp);
    $timestamp = strtotime('+1 day', $timestamp);
}

这篇关于如何在php中创建一个星期名称数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆