PHP 将 2d 数组排序为 3d 数组
我试图弄清楚如何在 PHP 中将 2d 数组排序为 3d 数组。该数组包含管理树中用户的任务,目前的排列方式如下:
Array ( [0] => Array ( [Title] => Test Task [Author] => 5 [DateIn] => 2010-09-15 [Deadline] => 2010-09-30 [Position] => 1 [Description] => This is a test task [Assignee] => 3 ) [1] => Array ( [Title] => Test Task [Author] => 5 [DateIn] => 2010-09-15 [Deadline] => 2010-09-29 [Position] => 1 [Description] => Blah blah [Assignee] => 3 ) )
我想对其进行排序,使其成为一个 3d 数组,其中每个第二级数组包含分配给一个用户的所有任务。有没有简单的方法可以做到这一点?我发现的最接近的是 array_multsort,但这并不能完全满足我的要求。
*编辑 这基本上是我目前工作的公司的任务管理器应用程序。经理需要能够查看已分配给员工的任务。我目前将员工和主管组织成一棵树,因此他们需要查看其分支中的所有内容。
现在,我编写的函数返回每个“经理”的员工的任务,不按特定顺序排序。为了减少混乱,我需要一次只能显示一个“员工”的任务。目前这是不可能的,因为数组的结构仅包含作者被标记为当前用户的所有任务的列表。
简而言之,我想将这些任务排序到一个 3 维数组中,其中每个二级数组包含属于当前用户的一名“员工”的任务。
I'm trying to figure out how to sort a 2d array into a 3d array in PHP. The array contains tasks from users in a management tree and is currently arranged like so:
Array ( [0] => Array ( [Title] => Test Task [Author] => 5 [DateIn] => 2010-09-15 [Deadline] => 2010-09-30 [Position] => 1 [Description] => This is a test task [Assignee] => 3 ) [1] => Array ( [Title] => Test Task [Author] => 5 [DateIn] => 2010-09-15 [Deadline] => 2010-09-29 [Position] => 1 [Description] => Blah blah [Assignee] => 3 ) )
I want to sort it so that it's a 3d array where each 2nd level array contains all of the tasks assigned to one user. Is there an easy way to do this? The closest thing I found was array_multsort, but that doesn't quite do what I want.
*Edits
This is basically a task manager app for the company I currently work for. Managers need to be able to see the tasks that have been assigned to their employees. I currently have employees and supervisors organized into a tree, so they need to see everything in their branch.
Right now, the function I've written returns the tasks for employees of each "manager" sorted in no particular order. To reduce clutter, I need to be able to only display one "employee's" tasks at a time. Currently this is not possible, as the structure of the array is such that it simply contains a list of all the tasks where the author is marked as the current user.
In short, I would like to sort these tasks into a 3 dimensional array, where each 2nd level array contains the tasks belonging to one "employee" belonging to the current user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不太明白你的意思,但如果你想生成一个新的数组,其中列出受让人的任务,那么你可以使用以下内容。
这将为您提供一个数组,其中键是受让人 ID,子数组是分配给他们的任务。
I don't quite understand what you're getting at, but if you want to produce a new array which lists tasks by assignee, then you can use the following.
This will give you an array where the keys are the assignee IDs and the sub arrays are the tasks assigned to them.
因此,如果我理解,您的数组将具有以下排列:
这是正确的吗?如果是这样,则假设“作者”是经理,“受让人”是员工,请尝试以下操作:
So if I understand, your array will have the following arrangement:
Is this correct? If so, then assuming "author" is the manager and "assignee" is the employee, try the following: