PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Awright dudes, have a wee problem with php. Maybe you lot can sort it out for me. I have this piece of code to check passenger ages against. However, when I ask the code if 0 is less than 2, it comes back false :S Heres the (ultra cut down version of the) offending code:
it's inadvisable to use a switch in this case, as expressions are a bit odd in case statements. Unless you can post more of the real code, I'd suggest using an if..
A little update: In case you're wondering why Im using Switches instead of IF statements, well...the code is a helluva lot more than just this little piece here... there are switches and nested Ifs everwhere and it seemed easier to do the switch statement. PS I have a larger snippet of the code here just to show you that it does work with anything other than a 0 value:
function findpriceEur($daystravel) { // Area A
switch ($daystravel) {
case $daystravel<=5:
$travelcost="5.49";break;
case $daystravel<=10:
$travelcost="7.32";break;
case $daystravel<=17:
$travelcost="9.16";break;
case $daystravel<=24:
$travelcost="10.53";break;
case $daystravel<=31:
$travelcost="11.43";break;
case $daystravel<=38:
$travelcost="14.63";break;
case $daystravel<=45:
$travelcost="17.39";break;
case $daystravel<=52:
$travelcost="20.12";break;
case $daystravel<=(31*2): // 2 months
$travelcost="25.16";break;
case $daystravel<=(31*3): // 3 months
$travelcost="29.72";break;
case $daystravel<=(31*4): // 4 months
$travelcost="36.59";break;
case $daystravel<=(31*5): // 5 months
$travelcost="45.75";break;
case $daystravel<=(31*6): // 6 months
$travelcost="52.60";break;
case $daystravel<=(31*7): // 7 months
$travelcost="64.03";break;
case $daystravel<=(31*8): // 8 months
$travelcost="73.18";break;
case $daystravel<=(31*9): // 9 months
$travelcost="82.34";break;
case $daystravel<=(31*10): //10 months
$travelcost="91.46";break;
case $daystravel<=(31*11): //11 months
$travelcost="98.34";break;
case $daystravel<=366: //12 months
$travelcost="105.19";break;
}
return $travelcost;
}
:S
And theres 8 of these...and plenty more functions etc on the page.
dang ! lol
Last edited by ihateevilbill on Wed Aug 11, 2004 3:15 am, edited 1 time in total.
feyd wrote:doing some checking it looks like, switch(0) always runs the default unless an exact match (case 0) is in the list.
switch evaluates the given expression and then compares its value to each of the cases. When you have to use boolean expression in case it's usually written as: