Php 如何完成数组日期
我有下一个数组:Php 如何完成数组日期,php,arrays,Php,Arrays,我有下一个数组: $data = [ ["1198","2500","cofee","01-01-2014"], ["5689","2500","cofee","15-01-2014"], ["2420","2500","cofee","31-02-2014"] ]; 使用此功能完成以下日期: function completeDates($array, $format=null){ $startdate = current($
$data =
[
["1198","2500","cofee","01-01-2014"],
["5689","2500","cofee","15-01-2014"],
["2420","2500","cofee","31-02-2014"]
];
使用此功能完成以下日期:
function completeDates($array, $format=null){
$startdate = current($array);
$startdate = $startdate[3];
$enddate = end($array);
$enddate = $enddate[3];
(is_int($startdate)) ? 1 : $startdate = strtotime($startdate);
(is_int($enddate)) ? 1 : $enddate = strtotime($enddate);
if($startdate > $enddate){
return false; //Fecha final es menor a la inicial
}
while($startdate < $enddate){
$fecha = date($format, $startdate);
$arr[$fecha] = ($format) ? ["aa"] : $startdate;
$startdate += 86400;
}
$arr[date($format, $startdate)] = ($format) ? end($array) : $enddate;
return $arr;
}
我有你的答案,但使用的是C#方法,因为我不太擅长jQuery 我希望你能翻译它,因为它工作得很好 我用西班牙语在代码中为您提供了一些注释
public static List<Siniestro> RellenarArregloFechas(List<Siniestro> Rellenar)
{
//ordenamos el arreglo a rellenar-----------------
for (int i = 1; i < Rellenar.Count; i++)
{
for (int j = 1; j < Rellenar.Count; j++)
{
if(Rellenar[j].Fecha > Rellenar[j+1].Fecha)
{
Siniestro aux = Rellenar[j];
Rellenar[j] = Rellenar[j + 1];
Rellenar[j + 1] = aux;
}
}
}
//--------------------------------------------------
//sacamos fecha inicial y final----------------------
DateTime Finicial = Rellenar[1].Fecha.Value;
DateTime Ffinal = Rellenar[Rellenar.Count].Fecha.Value;
//mientras fecha inicial (que ira aumentando un dia) sea menor a la final
// buscamos si no existe un siniestro con esa fecha inicial y si no existe
//agregamos al listado de sinistros un siniestro nuevo que tenga los mismos
// datos que el sinistro de la fecha un dia anterior a la fecha inicial en la que vamos,
// pero le agregamos un dia en su propiedad de fecha antes de agregarlo al List
while (Finicial < Ffinal)
{
if(!Rellenar.Any(f => f.Fecha == Finicial))
{
Siniestro aux = new Siniestro();
aux = Rellenar.Where(f => f.Fecha == Finicial.AddDays(-1)).FirstOrDefault();
aux.Fecha.Value.AddDays(1);
Rellenar.Add(aux);
}
Finicial = Finicial.AddDays(1);
}
return Rellenar;
publicstaticlist rellenarrelglofechas(List Rellenar)
{
//阿雷格洛酒店-----------------
for(int i=1;iRellenar[j+1].Fecha)
{
Siniestro aux=Rellenar[j];
Rellenar[j]=Rellenar[j+1];
Rellenar[j+1]=aux;
}
}
}
//--------------------------------------------------
//萨卡莫斯·费查国际酒店----------------------
DateTime Finicial=Rellenar[1]。Fecha.Value;
DateTime Ffinal=Rellenar[Rellenar.Count].Fecha.Value;
//在决赛中,海选将是一场重要的比赛
//不存在任何不符合中国国情的特殊情况
//在米斯莫斯的新城市中,有一个新的城市
//在瓦莫斯的一个特殊的地方,前面有一个中央的数据,
//这是一份关于农业的清单
while(财务f.Fecha==财务))
{
Siniestro aux=新的Siniestro();
aux=Rellenar.Where(f=>f.Fecha==fincial.AddDays(-1)).FirstOrDefault();
附加费价值增加天数(1);
新增(辅助);
}
财务=财务增加天数(1);
}
回归回归;
public static List<Siniestro> RellenarArregloFechas(List<Siniestro> Rellenar)
{
//ordenamos el arreglo a rellenar-----------------
for (int i = 1; i < Rellenar.Count; i++)
{
for (int j = 1; j < Rellenar.Count; j++)
{
if(Rellenar[j].Fecha > Rellenar[j+1].Fecha)
{
Siniestro aux = Rellenar[j];
Rellenar[j] = Rellenar[j + 1];
Rellenar[j + 1] = aux;
}
}
}
//--------------------------------------------------
//sacamos fecha inicial y final----------------------
DateTime Finicial = Rellenar[1].Fecha.Value;
DateTime Ffinal = Rellenar[Rellenar.Count].Fecha.Value;
//mientras fecha inicial (que ira aumentando un dia) sea menor a la final
// buscamos si no existe un siniestro con esa fecha inicial y si no existe
//agregamos al listado de sinistros un siniestro nuevo que tenga los mismos
// datos que el sinistro de la fecha un dia anterior a la fecha inicial en la que vamos,
// pero le agregamos un dia en su propiedad de fecha antes de agregarlo al List
while (Finicial < Ffinal)
{
if(!Rellenar.Any(f => f.Fecha == Finicial))
{
Siniestro aux = new Siniestro();
aux = Rellenar.Where(f => f.Fecha == Finicial.AddDays(-1)).FirstOrDefault();
aux.Fecha.Value.AddDays(1);
Rellenar.Add(aux);
}
Finicial = Finicial.AddDays(1);
}
return Rellenar;