switch case in php advanced - Web Development and Web Design Codes

Latest

Sunday, February 11, 2018

switch case in php advanced

switch case in php advanced

php Switch case
php Switch case

switch statements in php are used to perform different action based on different conditions practice below examples to understand php Switch case

Examples 1: PHP Switch Case Example:
<?php

class Anjan{
 function hello(){
  //Generating Random Numbers
  $this->num=mt_rand(1,4);
  switch($this->num){
   case '1':
   echo "You Have 1 Item";
   break;
   case'2':
   echo "You Have 2 Items";
   break;
   case'3':
   echo "You Have 3 Items";
   break;
   case'4':
   echo "You Have 4 Items";
   break;
  }
  
 }
}
?>
<?php
$obj=new Anjan();
echo $obj->hello();
?>
Examples 2: PHP Switch Case Example:

<?php
class Anjan{
 var $language;
 
 function hello(){
  switch($this->language){
   case 'English':
   echo "Your Language is English";
   break;
   case 'Bangla':
   echo "Your Language is Bangla";
   break;
   case 'Latin':
   echo "Your Language is Latin";
   break;
   case 'Polski':
   echo "Your Language is Polski";
   break;
   case 'Dutch':
   echo "Your Language is Dutch";
   break;
   case 'Hindi':
   echo "Your Language is Hindi";
   break;
  }
 }
}
?>
<form method="POST">
  Your Language:
  <select name="language">
     <option value="bangla">Bangla</option>
  <option value="English">English</option>
  <option value="Latin">Latin</option>
  <option value="Polski">Polski</option>
  <option value="Dutch">Dutch</option>
  <option value="Hindi">Hindi</option>
  </select>
  <input type="submit" name="submit" value="Set Language"/>
</form>
<?php
$obj=new Anjan();
if(isset($_POST['submit'])){
$obj->language=ucfirst($_POST['language']);
echo $obj->hello();
}
?>
I hope you understand php Switch case conditions .Keep visiting This blog for more codes.Please leave your Comment..Thank You..

No comments:

Post a Comment

Thank You for Your Comment

Note: Only a member of this blog may post a comment.