我有多个关联数组,如果除了 startdate
以外的所有值都相同,我想要将它们合并。如果两个数组确实相同,我想要合并它们并创建一个新元素 enddate
,以便显示日期范围的 startdate
和 enddate
。范围内的所有日期必须在原始数组中表示,即如果缺少日期,则其两侧的日期不得合并。
Array('color'=>'red','size'=>'large','shape'=>'circle','startdate'=>'2011-08-17')
Array('color'=>'red','size'=>'large','shape'=>'circle','startdate'=>'2011-08-18')
Array('color'=>'red','size'=>'large','shape'=>'square','startdate'=>'2011-08-20')
should become:
Array('color'=>'red','size'=>'large','shape'=>'circle','startdate'=>'2011-08-17','enddate'=>'2011-08-18')
Array('color'=>'red','size'=>'large','shape'=>'square','startdate'=>'2011-08-20')
到目前为止,我尝试循环遍历每个数组并创建多维数组:
foreach($arrays as $id => $array){
$mergearray[$array['red']][$array['large']][$array['circle']] = $id;
};
为了检查另一个数组是否具有相同的值。我正在尝试使用这些数组来重构原始结构中的数组。