简体   繁体   中英

Dynamically create multi multidimensional array while looping through foreach loop

This my array which contains employee role details, department details and permission details.

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
        )

)

In the above code block you can see [permission] => employee is same for [0] , [1] , [2] arrays too. But [permission_page] is different. So, I want a multidimensional array like shown below. Here, [permission] array contains all the [permission_page] . I want to implement my code in a similar fashion as shown below. Any help would be much appreciated.

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
        )

)

Get all values of permission and permission page, then loop on permission to get grouping permission wise pages.

$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 — Return the values from a single column in the input array

Here is working demo .

Use foreach then push each permission_page to $result with permission as key

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

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

I created below code. Hope It can help you. It gives exact output as u want.

 <?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; ?> 

Here is your solution

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'
        )
    );

Solution

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

?>

OUTPUT

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
        )

)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM