Hyaku_ Posted January 11, 2007 Share Posted January 11, 2007 Hi!is this posible?[code]switch($var){ case 1: if($something == $something_else){ jump_to_case_2; } break; case 2: ...... break;}[/code]Thanks! Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/ Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Nope. What are you trying to do exactly? Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-157985 Share on other sites More sharing options...
btherl Posted January 11, 2007 Share Posted January 11, 2007 It's not possible.. but you can do this:[code=php:0]switch($var) {case 1: if ($something != $something_else) { break; }case 2: .....break;}[/code]That will fall through to case 2 if $something == $something_else. Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-157986 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 case 2 still will not run unless $var == 2. Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-157992 Share on other sites More sharing options...
kenrbnsn Posted January 11, 2007 Share Posted January 11, 2007 That's not true.Try this example:[code]<?phpif (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=0Ken Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158004 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 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 https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158009 Share on other sites More sharing options...
kenrbnsn Posted January 11, 2007 Share Posted January 11, 2007 Leave out the 2nd "break" in "case 1:".Ken Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158016 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Still doesn't work. Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158018 Share on other sites More sharing options...
kenrbnsn Posted January 11, 2007 Share Posted January 11, 2007 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 https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158022 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 Yeah, Im aware of that, but read the question. Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158024 Share on other sites More sharing options...
Hyaku_ Posted January 11, 2007 Author Share Posted January 11, 2007 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 https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158028 Share on other sites More sharing options...
trq Posted January 11, 2007 Share Posted January 11, 2007 There is no such thing as goto in php [i]yet[/i]. Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158033 Share on other sites More sharing options...
Hyaku_ Posted January 11, 2007 Author Share Posted January 11, 2007 I didn't know that! Thanks! :-X Link to comment https://forums.phpfreaks.com/topic/33695-jump-from-one-case-to-another/#findComment-158040 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.