RE: [PHP] help with arrays

This is a discussion on RE: [PHP] help with arrays within the PHP General forums, part of the PHP Programming Forums category; Robert Cummings <mailto:robert@interjinn.com> on Tuesday, September 23, 2003 1:43 PM said: > It doesn'...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 09-23-2003
Chris W. Parker
 
Posts: n/a
Default RE: [PHP] help with arrays

Robert Cummings <mailto:robert@interjinn.com>
on Tuesday, September 23, 2003 1:43 PM said:

> It doesn't get much simpler :)


Doh!!

> foreach( $data as $key => $value )


I don't use that syntax much so I'm not familiar with it. Maybe I should
start eh?


Thanks,
Chris.
Reply With Quote
  #2 (permalink)  
Old 09-23-2003
Robert Cummings
 
Posts: n/a
Default Re: [PHP] help with arrays

On Tue, 2003-09-23 at 17:37, Eugene Lee wrote:
> On Tue, Sep 23, 2003 at 01:49:03PM -0700, Chris W. Parker wrote:
> :
> : Robert Cummings <mailto:robert@interjinn.com> said:
> : >
> : > foreach( $data as $key => $value )
> :
> : I don't use that syntax much so I'm not familiar with it. Maybe I should
> : start eh?
>
> Another caveat: it works on a *copy* of the array. This is fine for
> small arrays, but may be a performance killer for larger arrays.


I don't think you have enough knowledge of the PHP internals to make
that claim :) To qualify my statement, PHP doesn't not literally copy
data until you attempt to make a change. So in the above example $key
and $value are virtual copies of relevant data. If I were to try and
change either of these values then an explicit copy would be made at
that time, but not before. Thus since I actually make modifications on
the original $data array structure, my example makes no real copies
except when the new values is set in the original array. My example is
much more optimal than you think, mostly because of the oft unknown
optimizations made in the PHP engine itself.

Cheers,
Rob.
--
..------------------------------------------------------------.
| InterJinn Application Framework - http://www.interjinn.com |
:------------------------------------------------------------:
| An application and templating framework for PHP. Boasting |
| a powerful, scalable system for accessing system services |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for |
| creating re-usable components quickly and easily. |
`------------------------------------------------------------'
Reply With Quote
  #3 (permalink)  
Old 09-23-2003
Eugene Lee
 
Posts: n/a
Default Re: [PHP] help with arrays

On Tue, Sep 23, 2003 at 05:44:46PM -0400, Robert Cummings wrote:
: On Tue, 2003-09-23 at 17:37, Eugene Lee wrote:
: > On Tue, Sep 23, 2003 at 01:49:03PM -0700, Chris W. Parker wrote:
: > :
: > : Robert Cummings <mailto:robert@interjinn.com> said:
: > : >
: > : > foreach( $data as $key => $value )
: > :
: > : I don't use that syntax much so I'm not familiar with it. Maybe I should
: > : start eh?
: >
: > Another caveat: it works on a *copy* of the array. This is fine for
: > small arrays, but may be a performance killer for larger arrays.
:
: I don't think you have enough knowledge of the PHP internals to make
: that claim :)

You're right. I know little of PHP internals. I'm just going by what
little the official documentation tells me. :-)

http://www.php.net/manual/en/control...es.foreach.php

Note: Also note that foreach operates on a copy of the specified
array and not the array itself.
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 11:32 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0