Jump to content

[SOLVED] Getting values from array for a conditional loop


knox203

Recommended Posts

Hello everyone, I have a conditional statement inside of a do-while loop... before I get too ahead of myself, here's the code:

 

do
	{ 
if (	$fields['CustomerCode'] == "SYSCFOOD" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || 
		$fields['CustomerCode'] == "IVEYIMAG" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || 
		$fields['CustomerCode'] == "KAISLTC"  && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' ||
		$fields['CustomerCode'] == "KAISPERM" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || 
		$fields['CustomerCode'] == "EVERPHAR" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || 
		$fields['CustomerCode'] == "CONSPHAR" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || 
		$fields['CustomerCode'] == "QUESSTAT" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' || 
		$fields['CustomerCode'] == "LEGASTAT" && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00' ) { 
		$fields['DriverBaseAmount'] = $fields['DriverBaseAmount'] - 2.50; }
.......
} while ($fields = mssql_fetch_assoc($ic_result));

 

I need to add around 100 more company code names into this conditional statement, but I don't want the code to be huge! I figure there has to be a more efficient way of doing this. So can I add all of the company codes into an array, and just have one conditional statement look through the array while the do-while is looping? Thanks!

 

- Adam

Link to comment
Share on other sites

$codes = array('SYSCFOOD','IVEYIMAG','ETC');

do
	{ 
if (in_array($fields['CustomerCode'], $codes) && $job_date_name != "Sat" && $job_date_name != "Sun" && $fields['DriverBaseAmount'] > '14.00') { 
		$fields['DriverBaseAmount'] -= 2.50; }

} while ($fields = mssql_fetch_assoc($ic_result));

 

That should do the trick.

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.