Re: Re: check a variable after EACH function

From: Date: Wed, 01 Jul 2009 13:10:23 +0000
Subject: Re: Re: check a variable after EACH function
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-294791@lists.php.net to get a copy of this message
2009/7/1 Nisse Engström <news.NOSPAM.0ixbtqKe@luden.se>: > On Tue, 30 Jun 2009 18:31:54 -0500, Flint Million wrote: > >> Suppose I have some kind of check variable - say for example >> $abort_now. Or it could be a function. Something to be evaluated to a >> value. >> >> I want to execute a block of statements, but after EACH statement >> executes, check the value of $abort_now and if it is true, break; out >> of the block. >> >> Here's an example >> >> do { >>   do_something(); >>   do_something_else(); >>   do_another_thing(); >>   do_yet_another_thing(); >>   and_keep_doing_things(); >> } while ($abort_now != 1); > > I would have the functions return true or false and > do something like: > >  while (do_something()         && >         do_something_else()    && >         do_another_thing()     && >         do_yet_another_thing() && >         and_keep_doing_things()) >    ; > > > /Nisse > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I think you *could* do something like this: <?php $functions = array('do_something', 'do_something_else', 'do_another_thing', 'do_yet_another_thing', 'and_keep_doing_things'); foreach ($functions as $function) { $function(); if ($abort_now == 1) break; } ?> The catch is that in this case all the functions would have to accept the same parameters. Andrew

« previous php.general (#294791) next »