Jump to content

jump from one "case" to another?


Hyaku_

Recommended Posts

That's not true.

Try this example:
[code]<?php
if (isset($_GET['v']))
switch($_GET['v']) {
case '0':
echo 'zero<br>';
case '1':
echo 'one<br>';
case '2':
echo 'two<br>';
case '3':
echo 'three<br>';
default:
echo 'default<br>';
}
?>[/code]

Or in action at http://www.rbnsn.com/phpfreaks/case_test.php?v=0

Ken
Link to comment
Share on other sites

Well, this doesn't work?

[code]#!/usr/bin/php
<?php

    $a = 10;
    $v = 1;

    switch ($v) {
        case 1:
            if ($a == 10) {
                break;
            } 
        break;
        case 2:
            echo "this is two";
        break;
    } 

?>
[/code]
Link to comment
Share on other sites

It's not displaying anything since $a is 10 in your example, change it to something else:
[code]<?php
    $a = 20;
    $v = 1;

    switch ($v) {
        case 1:
            if ($a == 10) {
                break;
            } 
        case 2:
            echo "this is two";
        break;
    } 

?>[/code]

Ken
Link to comment
Share on other sites

Well, I was trying to acomplish this:
[code]

switch($mode){
      case "read_pm":
                  if(id_of_pm_doesn't_exist_in_the_db){
                            don't_display_error_just_jump_to_case_list_pm;
                  }
      break;

    case "list_pm":
              list_all_private_messages();
    break;

}[/code]
I know how it can be done in different way, but I just thought if it would be posible to go to case "list_pm" on error, it would be preatty clean, but I guess I could use [i]goto[/i], but I don't want to use it.. Thanks!
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.