Jump to content

php beginner Foreach loop


mavveton12

Recommended Posts

again, without knowing what each "thing" is it's not really possible to give an accurate example. A generic example would somthing along the lines of

foreach($topLevelArray as $subArray){
if(!isset($subArray['arrayKeyToCheck'] || empty($subArray['arrayKeyToCheck'])){
 runDataInsertFunction($subArray);
}
elseif(($subArray['nextKeyToCheck'] < $valueToCheckAgainst) && ($subArray['lastKeyToCheck'] > $valueToCheckAgainst)){
 sendEmailFunction($subArray);
}
else{
 runErrorFunction($errorDetails);
}
}

 

This is just a simplified version that is half way between your psudo-code and the actual code you would use and is assuming a multi-dimensional array as the initial $topLevelArray.

Link to comment
Share on other sites

Thanks man this was alot help man! iam trying to complete

Cron job task to notify users about low ad funds

 

Do u think i can complete it with your solution that u sent me

 

 

 

 

 

 

public function adFundNotificationTask() {

 

$SQL = array(

'findAdFundLowNotificationActive' => "SELECT a.accountId, a.publisherId FROM Account a WHERE a.adFundNotificationActive = true AND a.accountState in ('ACTIVE','ACTIVE_OBSERVATION')",

'findAdfundsByAccount' => "SELECT accountId, adFund FROM Account",

'findAdfunsNotificationData' => "SELECT accountId, amount FROM Account_Ad_Fund_Notification_Task",

 

);

 

 

 

foreach($topLevelArray as $subArray){

if(!isset($subArray['arrayKeyToCheck'] || empty($subArray['arrayKeyToCheck'])){

runDataInsertFunction($subArray);

}

elseif(($subArray['nextKeyToCheck'] < $valueToCheckAgainst) && ($subArray['lastKeyToCheck'] > $valueToCheckAgainst)){

sendEmailFunction($subArray);

}

else{

runErrorFunction($errorDetails);

}

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.