我在将此数组转换为可以使用的格式时遇到问题。还有一些额外的数据没有显示在我的foreach循环中。有人能看看我构建阵列的方式,告诉我我做错了什么吗?
将有多个部门和多个地点。位置取决于部门的位置数量。
foreach...
$arr[$db['name']] =
array($db['date'] =>
array($db['dept'] => (Need other departments to show)
array($db['location'] => $db) (Need more locations for above dept.)
)
);
给我:
Array
(
[training] => Array
(
[08-24-2011] => Array
(
[dept1] => Array <----------There is more than one department that should show
(
[dept1 Other] => Array <--There is more than one location that should show
(
[start_time] => 03:00
[end_time] => 19:00
)
)
)
)
)
这就是我想要的。我只需要知道如何对它进行排序,这样我的数组就会产生这个putput;
Array
(
[training] => Array
(
[08-24-2011] => Array
(
[dept1] => Array
(
[dept1 Other] => Array
(
[start_time] => 03:00
[end_time] => 19:00
)
[dept2 Other] => Array
(
[start_time] => 03:00
[end_time] => 19:00
)
)
[dept2] => Array
(
[dept1 Other] => Array
(
[start_time] => 03:00
[end_time] => 19:00
)
[dept2 Other] => Array
(
[start_time] => 03:00
[end_time] => 19:00
)
[dept3 Other] => Array
(
[start_time] => 03:00
[end_time] => 19:00
)
)
)
)
)
非循环obj或数组的var_dump是什么?
有几种可能性。这是对其中两个的攻击:
-
您循环的数据在foreach循环中不足以使用。我想这就是发生的事情:
$arr = array(); foreach( $dbObj as $db ) { //your loop goes here // }
在这种情况下,您需要转储$dbObj。这是一个2D阵列吗?也许它真的是3D的,而你没有足够的循环。。。
- 您的查询只从数据库中提取了一个项目。检查一下