For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > January 2008 > switch issue









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author switch issue
sublimino@gmail.com

2008-01-06, 7:00 pm

Hello all,

Having a problem with the behaviour of switch when mixing variable types. Eg

<?php
$page = 'review';
switch ($page) {
case 0:
echo "0";
break;
case 'review':
echo "review";
break;
}
?>

this code interprets $page as 0 in the switch. It's not a problem to
alter 'review' to a number, just less elegant. Can anybody shed a
little light on mixed variable types in switch statements please?
While browsing the manual I noticed it performs "loose comparison" but
that seems to be the same as == ?

Many thanks,


Andy
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com