Re: Foreach

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Jan 27, 2008 1:33 PM, Nathan Nobbe <quickshiftin@xxxxxxxxx> wrote:
> On Jan 23, 2008 8:02 AM, Eric Butera <eric.butera@xxxxxxxxx> wrote:
>
> > Maybe someday SPL will become part of the PHP manual too. ;)
> >
>
> ill admit, the doxygen documentation is a little daunting at first.  at
> least
> more so than phpDocumentor for example.  but once youve cruised around
>  the spl docs for a little while, you can see its truly amazing.  marcus has
> done a superb job with it!
> and, ive made a discovery.  im sure this is novice level, for people who
> actually
> have a clue what they are doing w/ spl, which unfortunately seems like next
> to
>  no one.   well, im getting to know it; anyway, i digress.
> DualIterator is not 'in' php, because well, its not written in c.  marcus
> has distributed
> several classes and procedural files along with the c code to round out the
> spl
>  extension.  the example code is included in the php source, so in order to
> use it
> youll have to download the source and unpack it.  you will find the example
> code
> beneath
> ext/spl/examples
>  in particular, the DualIterator class is in the
> dualiterator.inc
> file.  and now, for my last trick, an example of the DualIterator, to
> illustrate how simple
> it is, (and incidentally less error prone than rolling your own, since its
> been tested).
>
> <?php
> require('dualiterator.inc');
>
>  $leftSideArray = array('one' => 1, 'two' => 2, 'three' => 3, 'four' => 4);
>  $rightSideArray = array('one' => 'a', 'two' => 'b', 'three' => 'c', 'four'
> => 'd');
>
>  $di = new DualIterator(new ArrayIterator($leftSideArray), new
> ArrayIterator($rightSideArray));
>
> while($di->valid()) {
>         var_dump($di->key());
>         var_dump($di->current());
>         $di->next();
>  }
> ?>
>
> to test whether the arrays have the same number of keys and values; in this
> example all we
> would have to do is:
> $di->areEqual();
>
> -nathan
>

I was just pointing out how fragmented PHP5+ is.  Look at the docs on
SPL and the DOM stuff, it's horrible.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux