You should be able to contain your foreach statement within an if statement:
if (isset($menu))
{
foreach ($sub as $link => $name) (
$sublink .= "<li><a href='".$link."'>".$name."</a></li><br>";
}
else
{
print "menu variable not set"
}
Hope this helps.
Hugh
----- Original Message -----
From: "Dan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, June 11, 2002 2:59 PM
Subject: [PHP] How do I stop foreach if $menu not set??
> I Have worked out this, but when $menu is not set it does the foreach
> function anyway, and desplays an error.
>
> What Can I do to stop the foreach function from working if $menu is not
> set??
>
> <?
> if ($menu==(introduction)) {$sub = array(
> 'overview.php' => 'Overview',
> 'moreinfo.php' => 'More Info'
> );
> }
>
> #These parts are topics and there may be more than two.
>
> if ($menu==(support)) {$sub = array(
> 'sitemap.php' => 'Site Map',
> 'contact.php' => 'Contact Us'
> );
> }
>
> foreach ($sub as $link => $name) (
> $sublink .= "<li><a href='".$link."'>".$name."</a></li><br>";
> ?>
> <a href="?menu=introduction">Introduction</a><br>
> <? $introduction; ?><br>
>
> <a href="?menu=support">Support</a><br>
> <? $support; ?>
>
>
> -----------------------------------------
> Daniel Broome, siliconBLUE Ltd, Web Author,
> http://siliconblue.com
> Mob: 64-21-178-5120
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php