PHP Switch case not working

This Comment will be submitted for moderation and will not be accessible to other users until it has been approved.


20 points

I am trying to use a simple php switch case() statement below, but for some reason it is unable to function:

<?php
 
switch($ad)
{
 case 
"1";
      echo 
"This is first php switch case statement";
    break;
 case 
"2";
      echo 
"This is second php switch case statement";
    break;
default;
      echo 
"This is default php switch case statement";
    break;

?>

Hope someone can help and explain the reasons why
cheers,
Tim



28 points

Tim, your php switch case should end with colon (:) not semi-colon (;).


<?php
 
switch($ad)
{
 case 
"1"<b>:</b>
      echo 
"This is first php switch case statement";
    break;
 case 
"2"<b>:</b>
      echo 
"This is second php switch case statement";
    break;
default<
b>:</b>
      echo 
"This is default php switch case statement";
    break;

?>

Make sense?

Anonymous's picture
Created by Anonymous
11 points

That indeed worked. I am still learning.

Tim

Anonymous's picture
Created by Anonymous

Post Comment

  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <c>, <cpp>, <drupal5>, <drupal6>, <java>, <javascript>, <php>, <python>, <ruby>. Beside the tag style "<foo>" it is also possible to use "[foo]". PHP source code can also be enclosed in <?php ... ?> or <% ... %>.