我在php中有一个多维数组 看起来像这样:
Array
(
[0] => Array
(
[day] => 0
[periods] => Array
(
[0] => Array
(
[0] => 01:00
[1] => 01:30
)
[1] => Array
(
[0] => 02:30
[1] => 03:00
)
)
)
[1] => Array
(
[day] => 1
[periods] => Array
(
[0] => Array
(
[0] => 01:30
[1] => 02:00
)
)
)
" day"关键时刻到了那天[0] ="星期一" 而且"时期"密钥提供用户在同一天选择的小时。
所以在当天[0]有一个'期间'对存储小时的anthor数组提供的数组,开始01:00,结束01:30开始02:30,结束03:00
我尝试foreach循环这个数组但我找不到方法。 我想每小时输入这个值到mysql,如:
$sql = "INSERT INTO task_list (
task, day, hour
) VALUES (?, ?, ?)
";
ex:day:0 start 1:00,day:0 end 1:30
有什么建议吗?
答案 0 :(得分:0)
这是你的解决方案......
$array = array(
array(
'day' => 0,
'periods' => array(
array('01:00','01:30'),
array('02:00','03:00'),
)
),
array(
'day' => 1,
'periods' => array(
array('01:00','02:00')
)
)
);
//echo "<pre>";print_r($array);
$values = '"INSERT INTO task_list ( task, day, hour ) VALUES';
foreach($array as $row){
foreach($row['periods'] as $row1){
$values .= '("start","'.$row['day'].'","'.$row1[0].'"),("end","'.$row['day'].'","'.$row1[1].'"),';
}
}
$values .= ';"';
$values = str_replace(',;',';',$values);
echo $values;