【发布时间】:2019-04-04 08:08:00
【问题描述】:
我对来自 Web 服务的 SOAP 响应有疑问。响应是一个多维数组,每个员工具有不同的结构。
我尝试使用 foreach 循环检索所有值并将它们存储在 mysql 数据库中。
Array
(
[item] => Array
(
[0] => Array
(
[department_id] => 1
[department_name] => Sales
[department_shortname] => SA
[hours] => Array
(
[item] => Array
(
[activity_id] => 1
[start_date] => 2019-03-12
[end_date] => 2019-03-12
[start_time] => 10:00
[end_time] => 14:20
[hour_code] => 0
[foreign_hour_code] => 20
[amount] => 3.83
[type] => productive
[labor_cost] => 25.23
)
)
)
[1] => Array
(
[department_id] => 2
[department_name] => POS
[department_shortname] => POS
[hours] => Array
(
[item] => Array
(
[activity_id] => 1
[start_date] => 2019-03-12
[end_date] => 2019-03-12
[start_time] => 14:35
[end_time] => 17:00
[hour_code] => 0
[foreign_hour_code] => 20
[amount] => 2.42
[type] => productive
[labor_cost] => 24.67
)
)
)
)
)
Array
(
[item] => Array
(
[department_id] => 2
[department_name] => POS
[department_shortname] => POS
[hours] => Array
(
[item] => Array
(
[0] => Array
(
[activity_id] => 1
[start_date] => 2019-03-13
[end_date] => 2019-03-13
[start_time] => 07:30
[end_time] => 12:00
[hour_code] => 0
[foreign_hour_code] => 20
[amount] => 4.25
[type] => productive
[labor_cost] => 40.48
)
[1] => Array
(
[activity_id] => 1
[start_date] =>
[end_date] =>
[start_time] =>
[end_time] =>
[hour_code] =>
[foreign_hour_code] => 63
[amount] => 2
[type] => none
[labor_cost] => 0
)
)
)
)
我试过了,但我没有得到所有的数据。
foreach($array as $employees)
{
foreach($employees as $employee)
{
foreach($employee as $days)
{
foreach($days as $day)
{
foreach($day as $item)
{
foreach($item as $stores)
{
foreach($stores as $store)
{
foreach($store as $item1)
{
foreach($item1 as $item2)
{
foreach($item2 as $hours)
{
foreach($hours as $hour)
{
foreach($hour as $booking)
{
/*
Store in DB per time registration.
$hours['department_id']
$hours['department_name']
$hours['department_shortname']
$booking[activity_id]
$booking[start_date]
$booking[end_date]
$booking[start_time]
$booking[end_time]
$booking[hour_code]
$booking[foreign_hour_code]
$booking[amount]
$booking[type]
$booking[labor_cost]
*/
}
}
}
}
}
}
}
}
}
}
}
}
我想在每次注册时遍历所有元素并将它们存储在数据库中。
department_id |部门名称 |部门简称 |活动ID |开始日期 |结束日期 |开始时间 |结束时间 |小时代码 | foreign_hour_code |金额 |类型 |人工成本
【问题讨论】:
-
我可以猜到你想要什么。如果向我们展示您到目前为止所尝试的内容,将会有所帮助。它给了我们一些可以使用的东西。顺便说一句:数组远非“非结构化”。
-
@KIKOSoftware 我添加了我的尝试。但由于每个员工的结构不同,我无法获得所有结果。
-
我明白了,数组的结构并不总是完全相同,所以你不能对它做出死板的反应。而是对您遇到的领域做出反应。更难回答您的问题的是,我可以看到您只向我们展示了数组的一小部分,但我会试一试。