Hi staskoverflow community.
How can i improve next structure of PHP 5 code. A list of models $months (more than 12) $month->days (more than 31)
$day->clients a list of clients $day->someActions a list of actions for $clients
i need to invoke every $action for every $client. So my construction is:
<?php
foreach($monthes as $month) {
foreach($month->days as $day) {
foreach($day->clients as $client) {
foreach($day->actions as $action) {
$action->run($client);
}
}
}
} ?>
So there are four foreach loops, can i improve this code ?
Why do you want to move out of nested loops? the code you have is very clear to understand and if your objective is to optimize the performance of this method, then the approach I would go with would be:
do you have a break condition? What i mean by this is,
$result = $action->run($client); if("break_condition" == $result){ break; }
this should considerably reduce the number of iterations.