...

View Full Version : Using case



zenix
10-09-2009, 02:01 PM
Hello,
I have been learning php over the past year and have decided to put my knowledge to the test by volunteering to build a web site for a church. They need to be able to calculate shipping costs by zone. I have entered all the zip prefixes into 8 arrays, 1 array for each zone. A LOT of typing.

Anyway, I was thinking maybe I could use a case layout to determine which zone is being queried. The problem is, I have no clue where to start. Here is a small amount of what I have.


<?php
//Zip code
$zone =$_POST['zip'];
//zone 2 zips
$zone2 = array( '070', '071', '072','073','074','075','076','078','079','100','101','102','103','196');
$zone3=array('004','005','010','011','012','013','014','015','016','017','447',);
$zone4=array('025','026','040','041','042','043','619',');

then I plan to test for the zone chosen by this:

if(in_array($zone,$Zone2))
{
// They are in Zone 2
}


And then having the prices for shipping associated with the zone be displayed for the customer.

If someone could point me in the right direction I would really appreciate it.

tomws
10-09-2009, 02:32 PM
Are you asking how to use the switch statement (http://php.net/manual/en/control-structures.switch.php)?

zenix
10-09-2009, 02:45 PM
Sorry, I WAS referring to switch.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum