1 回答
TA贡献1834条经验 获得超8个赞
您需要将数组转换为示例中的格式。如果日期存在并且所有数组都相同,则任务非常简单 - 日期的每个条目必须包含三个条目 - 'average_position'、'search_visibility_index' 和 'click_potential' 以及相应的值。
这意味着您必须遍历每个数组,从元素 #0 中获取日期,将其用作键,并在元素 1 下添加相应的数组键及其值。
<?php
$yourFirstArray = ['name' => 'average_position', 'series' => [['2020-03-18', 36.27], ['2020-03-19', 36.23]];
$yourSecondArray = ['name' => 'search_visibility_index', 'series' => [['2020-03-18', 5.14], ['2020-03-19', 5.14]];
$yourThirdArray = ['name' => 'click_potential', 'series' => [['2020-03-18', 70.73], ['2020-03-19', 70.74]];
$average_position_series = $yourFirstArray['series'];
$search_visibility_index_series = $yourSecondArray['series'];
$click_potential_series = $yourThirdArray['series'];
$data = [];
foreach($average_position_series as list($date, $value)) {
$data[$date]['average_position'] = $value;
}
foreach($search_visibility_index_series as list($date, $value)) {
$data[$date]['search_visibility_index'] = $value;
}
foreach($click_potential_series as list($date, $value)) {
$data[$date]['click_potential'] = $value;
}
DB::table('mytable')->insert($data);
- 1 回答
- 0 关注
- 55 浏览
添加回答
举报