How can I hide the primary menu block to certain pages using PHP? I tried this code to hide the primary menu block from certain pages using the following code:

// Only show block from types array and nodes array
$match = FALSE;
// Which node types
$types = array('page' =&gt; 1);
// Which nodes (by nid)
$nodes = array(1, 13);
if (arg(0) == 'node' &amp;&amp; is_numeric(arg(1))) {
  $nid = arg(1);
  $node = node_load(array('nid' =&gt; $nid));
  $type = $node-&gt;type;
  if (isset($types[$type]) &amp;&amp; in_array($nid, $nodes)) {
        $match = TRUE;
  }
}
return $match;


Currently, the block is set to visible in the header section of the site; the theme being used  is the Bluemarine theme.

Is there anything else that needs to be done?

Print Screen



http://i.stack.imgur.com/m6y4I.jpg

Menu Print Screem



http://i.stack.imgur.com/yUBD2.jpg
You can do it from the block configuration


go to admin/build/block
search for the block and click "configure"
in the "Page specific visibility settings" click on "Show on only the listed pages"
write the page that you want this block to be visible on E.g "news" this will make that block visible on http://www.examble.com/news


Is that what you mean?

UPDATE:

if you want to control tha appearance programatically do the following

1- Disable the primary links block from "admin/build/block"

2- enable the primary links menu from your theme configuration (now i suppose you see the menu in all the pages and you want to specify the pages that you want this menu to appear in)

3- open page.tpl.php file 

4- go to line 24 you will find something like this 

&lt;?php if (isset($primary_links)) { ?&gt;&lt;?php print theme('links', $primary_links, array('class' =&gt; 'links', 'id' =&gt; 'navlist')) ?&gt;&lt;?php } ?&gt;


we will edit the following condition if (isset($primary_links)) 

now you should know something if you have url like this
http://yoursite.com/media/pictures

then the function arg(0) will return media and arg(1) will return pictures

another example 

http://yoursite.com/admin

then the function arg(0) will return the first argument in your url which is admin

now lets back to the condition if (isset($primary_links))

we will edit it ... we wanna say to drupal if the first argument is equal to something then appear the menu else disable the menu

suppose that you want the menu to appeare in the page user

then you will edit the if (isset($primary_links)) to be 

if (isset($primary_links) &amp;&amp; (arg(0) == 'user')  )

suppose that you want this menu to appeare in page user and page admin

if (isset($primary_links) &amp;&amp; (arg(0) == 'user' || arg(0) == 'admin')  )

one more advanced example... if you want the menu to appeare only in 
user/1 page and admin  page

if (isset($primary_links) &amp;&amp; ( (arg(0) == 'user' &amp;&amp; arg(1) == '1') || arg(0) == 'admin')  )

hope that will help you