I am trying to put together a script and need to be able to list a number of countries and to then say, in the script, if the country is listed in the above do something...

The problem is that I do not want to have to specify each and every country in the statement. - I literally want to be able to just say that if something is listed in the above list it should be handled as follows...

I have already tried using an array, foreach statement, and preg_match... but there literally seems to be no way of doing this in PHP. Can anyone suggest a workaround or something (preferably not Javascript) that will work with PHP to enable the functionality that I need?

Recommended Answers

All 2 Replies

Your statement of the problem isn't clear in terms of why it is a problem. If you have all of the countries in an array and you get a country as input (from a form?) then there should be no problem comparing the two and determining if it is in the list or not. You could use a while loop to go through the array and compare your country from the input to every country in the array. Your statement "...there literally seems to be no way of doing this in PHP." makes no sense unless there is something important missing from the definition of the problem.

This, more precisely, is the problem:

}  elseif ($info['country'] == 'Austria' ||
	$info['country'] == 'Belgium' ||
	$info['country'] == 'Bulgaria' ||
	$info['country'] == 'Cyprus' ||
	$info['country'] == 'Czech Republic' ||
	$info['country'] == 'Denmark' ||
	$info['country'] == 'Estonia' ||
	$info['country'] == 'Finland' ||
	$info['country'] == 'France' ||
	$info['country'] == 'Germany' ||
	$info['country'] == 'Greece' ||
	$info['country'] == 'Hungary' ||
	$info['country'] == 'Ireland' ||
	$info['country'] == 'Italy' ||
	$info['country'] == 'Latvia' ||
	$info['country'] == 'Lithuania' ||
	$info['country'] == 'Luxembourg' ||
	$info['country'] == 'Malta' ||
	$info['country'] == 'Netherlands' ||
	$info['country'] == 'Poland' ||
	$info['country'] == 'Portugal' ||
	$info['country'] == 'Romania' ||
	$info['country'] == 'Slovakia' ||
	$info['country'] == 'Slovenia') {


		if ($info['weight'] >= '0.000' && $info['weight'] <= '0.100' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '5.56', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.000' && $info['weight'] <= '0.100') {

			$custom = array($SmallPacketSurface => '0.99', $SmallPacketEurope => '1.31', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.101' && $info['weight'] <= '0.119' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '5.56', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.101' && $info['weight'] <= '0.119') {

			$custom = array($SmallPacketSurface => '1.32', $SmallPacketEurope => '1.31', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.120' && $info['weight'] <= '0.139' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '5.67', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.120' && $info['weight'] <= '0.139') {

			$custom = array($SmallPacketSurface => '1.32', $SmallPacketEurope => '1.42', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.140' && $info['weight'] <= '0.159' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '5.82', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.140' && $info['weight'] <= '0.159') {

			$custom = array($SmallPacketSurface => '1.32', $SmallPacketEurope => '1.57', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.160' && $info['weight'] <= '0.179' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '5.95', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.160' && $info['weight'] <= '0.179') {

			$custom = array($SmallPacketSurface => '1.32', $SmallPacketEurope => '1.70', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.180' && $info['weight'] <= '0.199' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.10', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.180' && $info['weight'] <= '0.199') {

			$custom = array($SmallPacketSurface => '1.32', $SmallPacketEurope => '1.85', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.200' && $info['weight'] <= '0.219' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.23', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.200' && $info['weight'] <= '0.219') {

			$custom = array($SmallPacketSurface => '1.66', $SmallPacketEurope => '1.98', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.220' && $info['weight'] <= '0.239' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.37', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.220' && $info['weight'] <= '0.239') {

			$custom = array($SmallPacketSurface => '1.66', $SmallPacketEurope => '2.12', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.240' && $info['weight'] <= '0.259' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.49', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.240' && $info['weight'] <= '0.259') {

			$custom = array($SmallPacketSurface => '2.00', $SmallPacketEurope => '2.24', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.260' && $info['weight'] <= '0.279' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.62', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.260' && $info['weight'] <= '0.279') {

			$custom = array($SmallPacketSurface => '2.00', $SmallPacketEurope => '2.37', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.280' && $info['weight'] <= '0.299' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.76', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.280' && $info['weight'] <= '0.299') {

			$custom = array($SmallPacketSurface => '2.00', $SmallPacketEurope => '2.51', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.300' && $info['weight'] <= '0.319' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.90', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.300' && $info['weight'] <= '0.319') {

			$custom = array($SmallPacketSurface => '2.32', $SmallPacketEurope => '2.65', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.320' && $info['weight'] <= '0.339' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.02', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.320' && $info['weight'] <= '0.339') {

			$custom = array($SmallPacketSurface => '2.32', $SmallPacketEurope => '2.77', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.340' && $info['weight'] <= '0.359' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.14', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.340' && $info['weight'] <= '0.359') {

			$custom = array($SmallPacketSurface => '2.65', $SmallPacketEurope => '2.89', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.360' && $info['weight'] <= '0.379' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.26', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.360' && $info['weight'] <= '0.379') {

			$custom = array($SmallPacketSurface => '2.65', $SmallPacketEurope => '3.01', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.380' && $info['weight'] <= '0.399' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.38', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.380' && $info['weight'] <= '0.399') {

			$custom = array($SmallPacketSurface => '2.65', $SmallPacketEurope => '3.13', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.400' && $info['weight'] <= '0.419' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.50', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.400' && $info['weight'] <= '0.419') {

			$custom = array($SmallPacketSurface => '3.00', $SmallPacketEurope => '3.25', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.420' && $info['weight'] <= '0.439' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.62', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.420' && $info['weight'] <= '0.439') {

			$custom = array($SmallPacketSurface => '3.00', $SmallPacketEurope => '3.37', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.440' && $info['weight'] <= '0.459' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.74', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.440' && $info['weight'] <= '0.459') {

			$custom = array($SmallPacketSurface => '3.33', $SmallPacketEurope => '3.49', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.460' && $info['weight'] <= '0.479' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.86', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.460' && $info['weight'] <= '0.479') {

			$custom = array($SmallPacketSurface => '3.33', $SmallPacketEurope => '3.61', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.480' && $info['weight'] <= '0.499' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '7.98', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.480' && $info['weight'] <= '0.499') {

			$custom = array($SmallPacketSurface => '3.33', $SmallPacketEurope => '3.73', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.500' && $info['weight'] <= '0.519' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.10', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.500' && $info['weight'] <= '0.519') {

			$custom = array($SmallPacketSurface => '3.65', $SmallPacketEurope => '3.85', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.520' && $info['weight'] <= '0.539' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.21', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.520' && $info['weight'] <= '0.539') {

			$custom = array($SmallPacketSurface => '3.65', $SmallPacketEurope => '3.96', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.540' && $info['weight'] <= '0.559' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.32', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.540' && $info['weight'] <= '0.559') {

			$custom = array($SmallPacketSurface => '3.99', $SmallPacketEurope => '4.07', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.560' && $info['weight'] <= '0.579' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.43', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.560' && $info['weight'] <= '0.579') {

			$custom = array($SmallPacketSurface => '3.99', $SmallPacketEurope => '4.18', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.580' && $info['weight'] <= '0.599' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.54', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.580' && $info['weight'] <= '0.599') {

			$custom = array($SmallPacketSurface => '3.99', $SmallPacketEurope => '4.29', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.600' && $info['weight'] <= '0.619' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.65', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.600' && $info['weight'] <= '0.619') {

			$custom = array($SmallPacketSurface => '4.33', $SmallPacketEurope => '4.40', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.620' && $info['weight'] <= '0.639' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.76', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.620' && $info['weight'] <= '0.639') {

			$custom = array($SmallPacketSurface => '4.33', $SmallPacketEurope => '4.51', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.640' && $info['weight'] <= '0.659' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.87', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.640' && $info['weight'] <= '0.659') {

			$custom = array($SmallPacketSurface => '4.65', $SmallPacketEurope => '4.62', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.660' && $info['weight'] <= '0.679' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '8.98', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.660' && $info['weight'] <= '0.679') {

			$custom = array($SmallPacketSurface => '4.65', $SmallPacketEurope => '4.73', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.680' && $info['weight'] <= '0.699' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.09', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.680' && $info['weight'] <= '0.699') {

			$custom = array($SmallPacketSurface => '4.65', $SmallPacketEurope => '4.84', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.700' && $info['weight'] <= '0.719' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.20', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.700' && $info['weight'] <= '0.719') {

			$custom = array($SmallPacketSurface => '5.32', $SmallPacketEurope => '4.95', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.720' && $info['weight'] <= '0.739' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.31', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.720' && $info['weight'] <= '0.739') {

			$custom = array($SmallPacketSurface => '5.32', $SmallPacketEurope => '5.06', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.740' && $info['weight'] <= '0.759' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.42', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.740' && $info['weight'] <= '0.759') {

			$custom = array($SmallPacketSurface => '5.66', $SmallPacketEurope => '5.17', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.760' && $info['weight'] <= '0.779' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.53', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.760' && $info['weight'] <= '0.779') {

			$custom = array($SmallPacketSurface => '5.66', $SmallPacketEurope => '5.28', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.780' && $info['weight'] <= '0.799' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.64', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.780' && $info['weight'] <= '0.799') {

			$custom = array($SmallPacketSurface => '5.66', $SmallPacketEurope => '5.39', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.800' && $info['weight'] <= '0.819' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.75', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.800' && $info['weight'] <= '0.819') {

			$custom = array($SmallPacketSurface => '5.98', $SmallPacketEurope => '5.50', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.820' && $info['weight'] <= '0.839' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.86', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.820' && $info['weight'] <= '0.839') {

			$custom = array($SmallPacketSurface => '5.98', $SmallPacketEurope => '5.61', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.840' && $info['weight'] <= '0.859' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '9.97', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.840' && $info['weight'] <= '0.859') {

			$custom = array($SmallPacketSurface => '6.32', $SmallPacketEurope => '5.72', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.860' && $info['weight'] <= '0.879' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '10.08', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.860' && $info['weight'] <= '0.879') {

			$custom = array($SmallPacketSurface => '6.32', $SmallPacketEurope => '5.83', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.880' && $info['weight'] <= '0.899' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '10.19', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.880' && $info['weight'] <= '0.899') {

			$custom = array($SmallPacketSurface => '6.32', $SmallPacketEurope => '5.94', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.900' && $info['weight'] <= '0.919' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '10.30', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.900' && $info['weight'] <= '0.919') {

			$custom = array($SmallPacketSurface => '6.66', $SmallPacketEurope => '6.05', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.920' && $info['weight'] <= '0.939' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '10.41', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.920' && $info['weight'] <= '0.939') {

			$custom = array($SmallPacketSurface => '6.66', $SmallPacketEurope => '6.16', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.940' && $info['weight'] <= '0.959' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '10.52', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.940' && $info['weight'] <= '0.959') {

			$custom = array($SmallPacketSurface => '6.98', $SmallPacketEurope => '6.27', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.960' && $info['weight'] <= '0.979' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '10.63', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.960' && $info['weight'] <= '0.979') {

			$custom = array($SmallPacketSurface => '6.98', $SmallPacketEurope => '6.38', $CIP => '0.00');


		} elseif ($info['weight'] >= '0.980' && $info['weight'] <= '0.999' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.49', $CIP => '0.00');

		} elseif ($info['weight'] >= '0.980' && $info['weight'] <= '0.999') {

			$custom = array($SmallPacketSurface => '6.98', $SmallPacketEurope => '6.49', $CIP => '0.00');


		} elseif ($info['weight'] == '1.000' && $info['total'] >= '5.00') {

			$custom = array($SignedForEurope => '6.60', $CIP => '0.00');

		} elseif ($info['weight'] == '1.000') {

			$custom = array($SmallPacketSurface => '6.98', $SmallPacketEurope => '6.60', $CIP => '0.00');


		} elseif ($info['weight'] >= '1.001' && $info['weight'] <= '5.000') {

			$custom = array($Courier5Kg => '17.50', $World70Kg => '18.25', $CIP => '0.00');

		} elseif ($info['weight'] >= '5.001' && $info['weight'] <= '10.000') {

			$custom = array($Courier10Kg => '23.50', $World70Kg => '18.25', $CIP => '0.00');

		} elseif ($info['weight'] >= '10.001' && $info['weight'] <= '25.000') {

			$custom = array($Courier25Kg => '22.50', $World70Kg => '18.25', $CIP => '0.00');

		} else {

			$custom = array($World70Kg => '18.25', $CIP => '0.00');

		} // End of if statement

} else {

	$custom = array($World70Kg => '18.25', $CIP => '0.00');

Where the } else { section is I need to be able to make that an } elseif {, instead, for anything that is not included in the above list of countries.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.