我有一个看起来像这样的数组:
Array
(
[0] => Array
(
[LogDate] => Wed , Nov 14 , 2012
[LogIDs] => 1,2
[LogContents] => Hello!,Hello 2...
[LogAuthors] => yan,yan
[LogTimes] => 12:00 AM,12:00 AM
)
[1] => Array
(
[LogDate] => Thu , Nov 15 , 2012
[LogIDs] => 3,4
[LogContents] => Hello world...,Hi world...
[LogAuthors] => jonathan,jonathan
[LogTimes] => 12:00 AM,12:00 AM
)
)
我想将其重组为如下所示:
Array
(
[0] => Array
(
[LogDate] => Wed , Nov 14 , 2012
[0] => Array
(
[LogIDs] => 1
[LogContents] => Hello!
[LogAuthors] => yan
[LogTimes] => 12:00 AM
)
[1] => Array
(
[LogIDs] => 2
[LogContents] => Hello 2...
[LogAuthors] => yan
[LogTimes] => 12:00 AM
)
)
[1] => Array
(
[LogDate] => Thu , Nov 15 , 2012
[0] => Array
(
[LogIDs] => 3
[LogContents] => Hello world...
[LogAuthors] => jonathan,jonathan
[LogTimes] => 12:00 AM
)
[1] => Array
(
[LogIDs] => 4
[LogContents] => Hi world...
[LogAuthors] => jonathan
[LogTimes] => 12:00 AM
)
)
)
这可能吗?
我试过喜欢(更新版本,工作):
$result = $this->mymodel->fetch_logs(1, 5, 0);
$new_array = array();
$inner_array = array();
$kounter = 0;
foreach($result as $row){
$new_array[] = array(
'LogDate' => $row['LogDate'],
);
$log_ids = explode(',',$row['LogIDs']);
$log_contents = explode(',',$row['LogContents']);
$log_authors = explode(',',$row['LogAuthors']);
$log_times = explode(',',$row['LogTimes']);
$counter = count($log_ids);
for($i=0; $i<$counter; $i++){
$inner_array = array(
'LogID' => $log_ids[$i],
'LogContent' => $log_contents[$i],
'LogAuthor' => $log_authors[$i],
'LogTime' => $log_times[$i]
);
//array_push($new_array, $inner_array);
$new_array[$kounter][$i] = $inner_array;
}
$kounter++;
}
但是我推送的 inner_array 比 [LogDate] 更高级别。它们应该与 LogDate 处于同一级别。知道如何实现这一目标吗?