PHP Conditional Statements Example

Today, We want to share with you PHP Conditional Statements Example.In this post we will show you PHP If-Else, Switch Case and shorthand Ternary operator example, hear for ternary operator php tutorial we will give you demo and example for implement.In this post, we will learn about php switch case greater than with an example.

PHP Conditional Statements Example

There are the Following The simple About html conditional statements if else Full Information With Example and source code.

  Laravel 5.8 Datatables Tutorial With Example

As I will cover this Post with live Working example to develop PHP- Swich case statement with conditional switch,, so the php if statement multiple conditions,
is used for this example is following below.

PHP If-Else, Switch Case Tutorials

PHP If-Else, Switch Case and shorthand Ternary operator example

In PHP, we have the following conditional statements:

  • If Statement
  • If-Else Statement
  • If-Elseif-Else Statement
  • Switch Statement

<?php

$a=35;
$str="Jigarshah";
$str1="ViratKohali";
$type="Group";

//if condition example
if($a==35){
	echo "value of a is 35";
	echo "<br>";
}

//if-else condition example
if($str1 == "ViratKohali"){
	echo "Hi ViratKohali";
	echo "<br>";
}else {
	echo "Hi There!";
	echo "<br>";
}

//if-else-if example

if($str == "ViratKohali"){
	echo "Hi ViratKohali";
	echo "<br>";
}else if($str == "Jigarshah"){
	echo "Hi Jigarshah";
	echo "<br>";
} else{
	echo "Hi There!";
	echo "<br>";
}

//switch statement example

switch ($type){
	case "Group":
		echo "Group Type";
		break; //for breaking switch condition
	case "Varible":
		echo "Varible Type";
		break;
	default:
		echo "Neither Group or Varible Type";
}
echo "<br>";




echo ($a == 35) ? "value of a is 35"."<br>":"";


echo ($str1 == "ViratKohali") ? "Hi ViratKohali"."<br>" : "Hi There!"."<br>";


echo ($str == "ViratKohali") ? "Hi ViratKohali"."<br>" : (($str == "Jigarshah") ? "Hi Jigarshah"."<br>" : "Hi Jigarshah"."<br>");


echo ($type == "Group") ? "Group Type" : (($type == "Varible") ? "Varible Type" : "Neither Group or Varible Type");
?>

Final Results:

value of a is 35
Hi ViratKohali
Hi Jigarshah
Group Type
value of a is 35
Hi ViratKohali
Hi Jigarshah
Group Type

Web Programming Tutorials Example with Demo

Read :

  javascript Form validation Source code

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about php switch case multiple values.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Reply

avatar
  Subscribe  
Notify of