Jump to content

php beginner Foreach loop


mavveton12

Recommended Posts

have you checked the manual pages on foreach()? Without some contextual information about what each of these statements and parameters are no one can give you an accurate translation of your psudo-code.

 

Also, if you are thinking about getting into programming, I suggest you have a look here http://en.wikipedia.org/wiki/CamelCase

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.

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);

}

}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.