Hi All,

It seems that while() does not allow you to copy arrays (eg $array2 =
$array1;) and foreach does not allow you to manipulate the array pointer. I
need to do both. My main question is can you manipulate the array pointer in
foreach? Bellow is a snipit of what I'm trying to do (it is doing my head
in!):

$many = $this->many->toArray();

$i = 0;

function loop($many){
foreach($many as $one){

$var = 'var' . $i; 

if($one['var'] == '$var){
$many2 = $many;

if($condition){
loop($many2);
}

}else{prev($many); $i++;

}
}




Waigani wrote:
> 
> Thanks Michael,
> 
> What I'm trying to get is a nested foreach LOOP. My work around does not
> do it. I'll play with yours and see if I can get it to loop.
> 
> Thanks,
> 
> 
> 
> 
> Michael B Allen-3 wrote:
>> 
>> On 10/8/07, Waigani <[EMAIL PROTECTED]> wrote:
>>> > can you nest foreach in the framework?
>>> >
>>> > eg in a view template:
>>> >
>>> > foreach($this->many as $one){
>>> > print_r($one);
>>> > foreach($this->many as $one){
>>> > print_r($one);
>>> > }
>>> > }
>> 
>> Hi Waigani,
>> 
>> Each iterator is specific to the object being operated on so just make
>> a copy of the array before you iterate over it. Also, you'll have to
>> use a separate variable for $one if it will be used in the outer loop.
>> 
>> Try this:
>> 
>> foreach ($this->many as $one) {
>>     $_many = $this->many;
>>     foreach ($_many as $_one) {
>>         print_r($_one);
>>     }
>> }
>> 
>> -- 
>> Michael B Allen
>> PHP Active Directory SPNEGO SSO
>> http://www.ioplex.com/
>> 
>> 
> 
> 

-- 
View this message in context: 
http://www.nabble.com/nested-foreach-tf4591373s16154.html#a13131209
Sent from the Zend Framework mailing list archive at Nabble.com.

Reply via email to