[Snippet] Getting all permission list index based on roles

Drupal handle permission through roles base assigning to user. One user could apply multiple roles. Each of roles specified various permission define in hook_permission(). To get list of index for all permission for one user, we could used this snippet.

  $roles = array(3 => 'Project Manager');
  $roles = $user->roles;
  $permissions= user_role_permissions($roles);

Then by using user_access, we can define custom arguments like below:

if(user_access("create project content")) {
 print '<a href="/node/add/project">New Project</a>';