在循环遍历foreach循环时动态创建多维多维数组

时间:2018-01-03 06:17:32

标签: php arrays multidimensional-array foreach while-loop

此我的数组包含员工角色详细信息,部门详细信息和权限详细信息。

Array
(
    [0] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 13
            [user_permission_id] => 9
            [permission] => employee
            [permission_page] => newemployee
        )
    [1] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 15
            [user_permission_id] => 11
            [permission] => employee
            [permission_page] => edit
        )

    [2] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 16
            [user_permission_id] => 12
            [permission] => employee
            [permission_page] => update
        )

    [3] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 6
            [user_permission_id] => 16
            [permission] => suggestion

            [permission_page] => view
        )

    [4] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 7
            [user_permission_id] => 18
            [permission] => evaluation
            [permission_page] => index
        )

    [5] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 9
            [user_permission_id] => 25
            [permission] => leave
            [permission_page] => newrequest
        )

    [6] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 10
            [user_permission_id] => 26
            [permission] => leave
            [permission_page] => create
        )

    [7] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 17
            [user_permission_id] => 27
            [permission] => leave
            [permission_page] => viewall
        )

    [8] => stdClass Object
        (
            [role_id] => 3
            [role_name] => team leader
            [role_description] => Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market
            [role_department_id] => 2
            [department_id] => 2
            [department_name] => brand centrical
            [department_description] => Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.
            [user_role_permission_id] => 11
            [user_permission_id] => 28
            [permission] => leave
            [permission_page] => response
        )

)

在上面的代码块中,您可以看到[permission] => employee[0][1]数组的[2]也相同。但是[permission_page]是不同的。所以,我想要一个如下所示的多维数组。这里,[permission]数组包含所有[permission_page]。我想以类似的方式实现我的代码,如下所示。任何帮助将非常感激。

Array
(
    [employee] => Array
        (
            [0] => newemployee
            [1] => edit
            [2] => update
        )

    [suggestion] => Array
        (
            [0] => view
        )

    [evaluation] => Array
        (
            [0] => index
        )

    [leave] => Array
        (
            [0] => newrequest
            [1] => create
            [2] => viewall
            [3] => response
        )

)

4 个答案:

答案 0 :(得分:3)

获取权限和权限页面的所有值,然后循环获取权限以获取分组权限明智页面。

$permission = array_column($arr, 'permission');
$permission_page = array_column($arr, 'permission_page');
$result = [];
foreach($permission as $k => $v){
    $result[$v][] = $permission_page[$k]; 
}
print_r($result);

array_column - 返回输入数组中单个列的值

以下是demo

答案 1 :(得分:1)

使用foreach然后将每个permission_page推送到$result,并将permission作为关键

$result = [];
foreach ($array as $object) {
    $result[$object->permission][] = $object->permission_page;
}

echo '<pre>';
print_r($result);

答案 2 :(得分:1)

我创建了以下代码。希望它可以帮到你。它可以根据需要提供精确的输出。

&#13;
&#13;
<?php
$data = [];
$data[] = Array(
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 13,
            'user_permission_id' => 9,
            'permission' => 'employee',
            'permission_page' => 'newemployee'
        );
  $data[] = Array(
  'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 15,
            'user_permission_id' => 11,
            'permission' => 'employee',
            'permission_page' => 'edit',
        );
	$data[] = Array( 
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' =>' Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 16,
            'user_permission_id' => 12,
            'permission' => 'employee',
            'permission_page' => 'update',
        );

  $data[] =  array
        (
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' =>' brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 6,
            'user_permission_id' => 16,
            'permission' => 'suggestion',

            'permission_page' => 'view',
        );

  $data[] =  array
        (
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' =>' Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 7,
            'user_permission_id' => 18,
            'permission' => 'evaluation',
            'permission_page' => 'index',
        );

    $data[] = array
        (
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 9,
            'user_permission_id' => 25,
            'permission' => 'leave',
            'permission_page' => 'newrequest',
        );

     $data[] = array
        (
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' =>' Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 10,
            'user_permission_id' => 26,
            'permission' => 'leave',
            'permission_page' => 'create',
        );

   $data[] =  array
        (
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' =>' Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 17,
            'user_permission_id' => 27,
            'permission' => 'leave',
            'permission_page' => 'viewall',
        );

    $data[] = array
        (
            'role_id' => 3,
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => 2,
            'department_id' => 2,
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => 11,
            'user_permission_id' => 28,
            'permission' => 'leave',
            'permission_page' => 'response',
        );


foreach($data as $d)
{
    $var = $d['permission'];
	$data1["'".$var."'"][] = $d['permission_page'];
	
}
echo '<pre>';print_r($data1);echo '</pre>';exit;	
?>
&#13;
&#13;
&#13;

答案 3 :(得分:1)

这是您的解决方案

<强> INPUT

<?php 
    $array = array(
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '13',
            'user_permission_id' => '9',
            'permission' => 'employee',
            'permission_page' => 'newemployee'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '15',
            'user_permission_id' => '11',
            'permission' => 'employee',
            'permission_page' => 'edit'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '16',
            'user_permission_id' => '12',
            'permission' => 'employee',
            'permission_page' => 'update'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '6',
            'user_permission_id' => '16',
            'permission' => 'suggestion',
            'permission_page' => 'view'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '7',
            'user_permission_id' => '18',
            'permission' => 'evaluation',
            'permission_page' => 'index'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '9',
            'user_permission_id' => '25',
            'permission' => 'leave',
            'permission_page' => 'newrequest'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '10',
            'user_permission_id' => '26',
            'permission' => 'leave',
            'permission_page' => 'create'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '17',
            'user_permission_id' => '27',
            'permission' => 'leave',
            'permission_page' => 'viewall'
        ),
        array(
            'role_id' => '3',
            'role_name' => 'team leader',
            'role_description' => 'Competently brand orthogonal e-tailers vis-a-vis just in time manufactured products. Interactively extend performance based relationships for ubiquitous total linkage. Collaboratively fabricate stand-alone customer service whereas flexible growth strategies. Assertively harness fully tested e-market',
            'role_department_id' => '2',
            'department_id' => '2',
            'department_name' => 'brand centrical',
            'department_description' => 'Distinctively implement turnkey action items without distributed e-business. Globally visualize reliable core competencies via optimal imperatives. Seamlessly revolutionize standards compliant partnerships rather than functionalized convergence. Intrinsicly expedite intuitive functionalities after frictionless e-services. Seamlessly impact user-centric core competencies for resource sucking processes.',
            'user_role_permission_id' => '11',
            'user_permission_id' => '28',
            'permission' => 'leave',
            'permission_page' => 'response'
        )
    );

<强>解决方案

    $new = array();
    foreach($array as $r) $new[$r['permission']][] = $r['permission_page'];
    echo '<pre>';print_r($new);

?>

<强>输出

Array
(
    [employee] => Array
        (
            [0] => newemployee
            [1] => edit
            [2] => update
        )

    [suggestion] => Array
        (
            [0] => view
        )

    [evaluation] => Array
        (
            [0] => index
        )

    [leave] => Array
        (
            [0] => newrequest
            [1] => create
            [2] => viewall
            [3] => response
        )

)