[PHP] foreach with methods returning arrays ??? any ideas ?

2002-08-17 Thread Ipa
Have a strange problem with methods.. if i use function to return some array and doing 2-level nested foreach(), for example function x(){ return array(1, 2,3); } foreach(x() as $key){ echo $key .br; foreach(x() as $key2){ echo nbsp;nbsp; . $key2 . br; } } everything works fine ... the

Re: [PHP] foreach with methods returning arrays ??? any ideas ?

2002-08-17 Thread Rasmus Lerdorf
The code is very different. In your x() function you create a new array every time you call x(). In the class example, you create the array once when you instantiate the class and then return that same array each time you call the gety() method. When PHP iterates over arrays, it maintains an

Re: [PHP] foreach with methods returning arrays ??? any ideas ?

2002-08-17 Thread Ipa
yes there is difference in creation returning array.. but i talk about other thing IMHO 1. return returns COPY of array in both cases .. no difference is it method or function 2. here we don't return reference to the same array. 3. foreach - as i have read in most sources Makes a copy of given