|  | Posted by Hendri Kurniawan on 04/20/07 05:53 
Steve wrote:> "Hendri Kurniawan" <ask-me@email.com> wrote in message
 > news:132gjjaof54gv5a@corp.supernews.com...
 >
 > thanks hendri. btw, i didn't know you could do:
 >
 > foreach($value as $key=>$value)
 >
 > and expect to have the first $value preserved. i suppose though, thinking
 > about it, php gets a single reference to the $value array and then works off
 > the stack at that address. the second $value should be a new copy of the
 > element at $key - the next loop still working from the old stack and not the
 > new value of $value.
 >
 > it's not so much that i want an alternative, it's that i want to understand
 > exactly why the hack works yet the straight-forward approach does not - even
 > though the docs say it should. i'm just using array_walk to benchmark
 > data-retrieval in a custom db class...rather than using a foreach on the
 > records returned, i'd be trying to walk the records - goal being to
 > standardize access methods, i.e. $records[0]['FOO'] as the structure...a row
 > and field as keys. the foreach is pretty fast over 200K rows...just wanna
 > see how much faster the native iteration is over the native enumeration. :)
 > i'm just wierd like that.
 >
 > anyway, the code i posted here was me just playing with array_walk in a
 > practical scenario. just trying to find out about what all i could do with
 > the userdata param. that's when i ran into this bit of undefined behavior.
 > and, isn't it wonderful that it is undefined yet a single character's
 > correction would fix the problem - that character being '&' as a call-time
 > by-reference.
 >
 > thanks for the help.
 >
 >
 
 
 Yeah, glad to help.. It also challenges my mind not to be complacent.
 
 Hendri
  Navigation: [Reply to this message] |