2012-01-16 128 views
-1

我有对象的数组PHP数组对象转换

([date]=>2012-01-09, [count]=>5), 
([date]=>2012-01-11, [count]=>7), 
([date]=>2012-01-12, [count]=>5) 

什么是数组的数组对象或数组转换

([date]=>2012-01-08, [count]=>0), 
([date]=>2012-01-09, [count]=>5), 
([date]=>2012-01-10, [count]=>0), 
([date]=>2012-01-11, [count]=>7), 
([date]=>2012-01-12, [count]=>5), 
([date]=>2012-01-13, [count]=>0), 
([date]=>2012-01-14, [count]=>0) 

假设给定的起始日期2012-01-08最好的办法和结束日期2012-01-14

回答

1
  1. 生成从STARTDATE日期ENDDATE
  2. 创建一个空关联数组来存储您的日期数据。
  3. 遍历#1中的一个所产生的所有的日期由一个
  4. 如果在初始阵列存在对于当前日期的计数,存储的是,在#2创建的数组,否则存储计数为0时,与阵列键为(string) $currentDate
  5. 步骤#2的数组现在将具有所需的数据。

转换成PHP代码:)

0

这个我不会为你写的代码,但我会为您提供的算法

$compArray = new array(); 

loop from startdate to enddate as date 
{ 
    if (in_array(date, yourarray)) 
     copy the entry from yourarray to compArray 
    else 
     enter date into compArray with a count of 0 
}