What’s missing with Switch Statement?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rahulephp
    New Member
    • Sep 2009
    • 59

    #1

    What’s missing with Switch Statement?

    In below switch statement, it should have to print only "T","E","S" characters as string "testing" contains these words.
    But it is printing all characters including "X" and "Z".
    I can’t use "break;" because it will break operation after first case. (After matching "T" with word "testing") but I want to continue the operation even after every case to find the next character.

    Please advice if anything is missing.


    Code:
    switch(true)
    {
    	case stristr('testing','t'):
    	echo "T"."<br>";
    	
    	case stristr('testing','x'):
    	echo "X"."<br>";
    	
    	case stristr('testing','e'):
    	echo "E"."<br>";
    	
    	case stristr('testing','z'):
    	echo "Z"."<br>";
    	
    	case stristr('testing','s'):
    	echo "S"."<br>";
    }
  • zorgi
    Recognized Expert Contributor
    • Mar 2008
    • 431

    #2
    If you don't have break statement at the end of case than php will go on executing the statements of the following case. switch

    Comment

    Working...