我有一個這樣的數組:推多了一個元素數組PHP
return array(
'User Management -> Role Management' => array(
array(
'permission' => 'role-management.view',
'label' => 'View',
),
array(
'permission' => 'role-management.create',
'label' => 'Create',
),
array(
'permission' => 'role-management.edit',
'label' => 'Edit',
),
array(
'permission' => 'role-management.delete',
'label' => 'Delete',
),
),
'User Management -> User Management' => array(
array(
'permission' => 'user-management.view',
'label' => 'View',
),
array(
'permission' => 'user-management.create',
'label' => 'Create',
),
array(
'permission' => 'user-management.edit',
'label' => 'Edit',
),
array(
'permission' => 'user-management.delete',
'label' => 'Delete',
),
),
);
我已經成功地訪問該數組像這樣:
$permissions = Config::get('permissions');
我想補充以下label
新指標。我已經嘗試過,但無法添加。 `的foreach($權限$許可){
foreach ($permission as $eachPermission) {
$encodedPermission = base64_encode($eachPermission['permission']);
// $eachPermission['encodedPermission'] = $encodedPermission;
array_push($eachPermission, "encodedPermission", $encodedPermission);
}
}
var_dump($permissions); `
我嘗試了這些,但不能設置新的索引。我的預期結果是這樣的:
'permission' => 'role-management.view',
'label' => 'View',
'encodedPermission' => 'someencodedstring'
我是做錯了還是錯過了一些東西。