Re: [PHP4BETA] problems with array_walk
| From: | Sergio Garcia Murillo | Date: | Thu, 13 Apr 2000 16:19:46 +0000 |
| Subject: | Re: [PHP4BETA] problems with array_walk | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.version4 |
| Request: | Send a blank email to php-version4+get-13511@lists.php.net to get a copy of this message | ||
> > You might be running a loop and for some condition you want
> > to pass it to array_walk for the rest of the entries..... Better
> > explain by example:
> >
> > $a = array ( "faisal" , "nasim" , "whiz" , "kid"
> > , "FLAG" , "value" ,
> > "value2" );
> >
> > while ( $x = current ( $a ) )
> > {
> > if ( $x == 'FLAG' )
> > {
> > next ( $a );
> > array_walk ( $a , 'blah' ); // don't want to reset!
> > break;
> > }
> > print "ORDINARY VALUE: $x\n";
> > next ( $a );
> > }
> >
> > function blah ( &$val )
> > {
> > print "=== CAUGHT SECRET VALUE $val\n";
> > }
> >
> >
> > Output:
> >
> > ORDINARY VALUE: faisal
> > ORDINARY VALUE: nasim
> > ORDINARY VALUE: whiz
> > ORDINARY VALUE: kid
> > === CAUGHT SECRET VALUE value
> > === CAUGHT SECRET VALUE value2
>
> Seems like a pretty contrived example...
>
I think it's quite odd..
so why not make the array_walk reset by default and add an optional
parameter to
set it not to reset?? and what about a reverse_array_walk?? :)
Greetings
Sergio