3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $implicitConfig = [ 'READ_OWN' => [ 'READ', 'WRITE_OWN', 'WRITE', 'MANAGE_OWN', 'MANAGE' ], 'READ' => [ 'WRITE', 'MANAGE' ], 'WRITE_OWN' => [ 'WRITE', 'MANAGE_OWN', 'MANAGE' ], 'WRITE' => [ 'MANAGE' ], 'MANAGE_OWN' => [ 'MANAGE' ], 'MANAGE' => [] ]; $permission = "PERM_MODULE_TASKS_MANAGE"; $config = $implicitConfig; $endOptions = implode('|', array_keys($config)); // /^PERM_MODULE_([A-Z_]*)_(READ_OWN|READ|WRITE_OWN|WRITE|MANAGE_OWN|MANAGE)$/ $pattern = "/^PERM_MODULE_([A-Z_]*)_({$endOptions})$/"; $result = [$permission]; if (preg_match($pattern, $permission, $matches)) { $moduleName = $matches[1]; $permissionPostFix = $matches[2]; $permissionsImplicitlyContainingInputPermission = array_map(function($permissionPostfix) use ($moduleName) { return "PERM_MODULE_{$moduleName}_{$permissionPostfix}"; }, $config[$permissionPostFix]); $result = array_merge($result, $permissionsImplicitlyContainingInputPermission); } var_dump($result);
based on MKYZZ
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.2.6
array(1) { [0]=> string(24) "PERM_MODULE_TASKS_MANAGE" }