[thelist] best way to do dynamic tabs in PHP

Aleem Bawany aleem.bawany at utoronto.ca
Wed Jan 22 22:06:01 CST 2003


>> $pages = array("one.php", "two.php", ..., "six.php");
>>   foreach ($pages as $page) { if ($page != $currpage)
>>     // code for regular link
>>   else
>>     // code for current link
>> }
>
[...]

> matched, any ensuing pages won't match). Is there any way
> of stopping the foreach loop once the current page is

just use a while loop:

// this loop will stop as soon as it find one.php
// and c will have it's index
$c=0
while ($pages[c] != "one.php") {
	// normal link
	c++;
}
print $pages[c]; // this will print one.php


avoid break statements when you can. They break the
flow of code and are usually avoided because they
can create obscure conditions:

for (...)
	if (...) {
	...
	break;	// does this break the FOR or IF?
	}
}

I think there were some other criticisms, but I don't
remember them.

aleem

[ http://members.evolt.org/aleem/ ]




More information about the thelist mailing list