How to get the nid of current node I need a function to return the nid of the current node that the current user is watching.
Can you help me?
If you are insisting on a function then you are looking for arg function.

arg(0) will return 'node' and arg(1) will return node nid.

Provided you must be inside a node.

[Updated Answer]

if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
  $nid = arg(1);
  if ($nid) {
    $node = node_load($nid);
    /** do something **/  
  }
}


Alternately

you can get nid from node object $node-&gt;nid