TheQuestioner
Programmer
Greetings my fellow coding overlords.
I have slight problem with a PHP page that I am currently coding. I'm trying to determine the value of a specific variable using the SWITCH statement, and then altering the value of this same variable within the SWITCH statement. However I can't seem to change the value. My code is as follows
Generally the code works, but if I pass in 4 or 8, I'm expecting it to show
or
but I only get a number returned. Has this got something to do with variable scoping? Or does PHP automatically convert the variable into a number type?
I have slight problem with a PHP page that I am currently coding. I'm trying to determine the value of a specific variable using the SWITCH statement, and then altering the value of this same variable within the SWITCH statement. However I can't seem to change the value. My code is as follows
Code:
<?PHP
//some processing happens here
//store GET POST value into variable
//(This should be numeric)
$intOrder= $_GET["order"];
//validate passed column val
switch ($intOrder)
{
case $intOrder==(3||7||9): //other columns
break;
case $intOrder==(4||8): //date columns
[highlight]$intOrder.=" DESC";[/highlight]
break;
//any other value, then default to sort by gallery
//description
default:
$intOrder="4 DESC";
break;
};
echo $intOrder;
?>
Generally the code works, but if I pass in 4 or 8, I'm expecting it to show
Code:
4 DESC
or
Code:
8 DESC
but I only get a number returned. Has this got something to do with variable scoping? Or does PHP automatically convert the variable into a number type?