0

I am using this code sample to generate links to a couple of random, website subpages. The issue I have with this method, is for example when I go to /test123 page, there's a big chance that this code will generate link to the same exact page.

What I want to do is to somehow exclude currently displayed page from random links pool.

How can I achieve this?

<?php
$links = array(array('url' => '/asd', 'name'=>'Go to Asd'),
               array('url' => '/test', 'name' => 'Go to Test'),
               array('url' => '/test123', 'name' => 'Go to Test123'));
$num = array_rand($links);
$item = $links[$num];

printf('<a href="%s" title="%s">%s</a>', $item['url'], $item['name'], $item['name']);
?>
Andy Andy
  • 279
  • 4
  • 7
  • 17

1 Answers1

0

What I want to do is to somehow exclude currently displayed page from random links pool.

I'd just remove this url from $links prior calling array_rand().

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141