PHP scope question

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2010-05-21T09:05:31Z Indexed on 2010/05/21 9:10 UTC
Read the original article Hit count: 231

Filed under:
|
|

Hi,

I'm trying to look through an array of records (staff members), in this loop, I call a function which returns another array of records (appointments for each staff member).

foreach($staffmembers as $staffmember)
{   
        $staffmember['appointments'] = get_staffmember_appointments_for_day($staffmember);
        //  print_r($staffmember['appointments'] works fine 
}

This is working OK, however, later on in the script, I need to loop through the records again, this time making use of the appointment arrays, however they are unavailable.

foreach ($staffmembers as $staffmember)
{                                                             
        //do some other stuff
        //print_r($staffmember['appointments'] no longer does anything
}

Normally, I would perform the function from the first loop, within the second, however this loop is already nested within two others, which would cause the same sql query to be run 168 times.

Can anyone suggest a workaround?

Any advice would be greatly appreciated.

Thanks

© Stack Overflow or respective owner

Related posts about php

Related posts about scope