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
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
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
3 matches
Mail list logo