Reply to Re: PHP equiv of perl's last label or goto?

Your name:

Reply:


Posted by NC on 03/07/06 20:38

bobmct wrote:
>
> In a multiple nested structure I have a section that when true need to
> break out of not only the current structure, but several more to read
> a much higher level. In perl I would name/label my structures and use
> the "last labelname" statement to accomplish this.
>
> The PHP docs state that its break statement can take an optional
> parameter which represents the "number" of levels to break out of.
> Now this seems like it could work. However, I see a problem with
> ongoing maintenance if someone inserts or removes another level which
> would cause that number to be inaccurate.
>
> Can someone please recommend how one might accomplish this feat
> using flexible php code? I am all ears (well, eyes).

Put the code into a function and break out using return().
Alternatively, use a flag variable:

$flag = true;
while ($flag) {
// some PHP code...
if ($some_condition) {
$flag = false;
}
// more PHP code...
if ($another_condition) {
$flag = false;
continue;
}
// yet more PHP code...
}

Cheers,
NC

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация