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

$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.

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.