Connect with us

PHP

PHP if…else

mm

Published

on

If…Else are used to execute dissimilar procedures based on different conditions.
if Condition:-
The if condition executes some code if one condition is true.
Syntax:-
if (condition) {
execution code if condition is true
;
}
Example:-
<?php
$dt = date(“H”);

if ($dt < “2”) {
echo “the current time is 2 o clock”;
}
?>
if…else Condition:-
The if….else condition executes some code if one condition is true and another code if condition is false.
Syntax:-
if (condition) {
execution code if condition is true;
} else {
 execution code if condition is false;
}
Example:-
<?php
$dt = date(“H”);

if ($dt < “2”) {
echo “the current time is 2 o clock”;
} else {
echo “the current time is not 2 o clock”;
}
?>
if…elseif….else Condition:-
The if….elseif…else condition executes different codes for more than two conditions.
Syntax:-
if (condition) {
execution code if this condition is true;
} elseif (condition) {
 execution code if this condition is true;
} else {
execution code if all conditions are false;
}
Example:-
<?php
$dt = date(“H”);

Also Read :   PHP Variables

if ($dt < “1”) {
echo “the current time is not 2 o clock”;
} elseif ($dt < “2”) {
echo “the current time is 2 o clock”;
} else {
echo “the current time is not 2 o clock”;
}
?>

Hi, Thank you for reading my article. I am Victor, a professional blogger from Jaipur, India.I started webetutorial for blogging & sharing solution for developer questions, and now it’s empowering globally by helping them to make money.I am writing about starting & managing a blogs, WordPress, Magento, Social Media, SEO, Marketing, making money online, Investment, Finance, Gadgets, Fitness and more.

Continue Reading
Advertisement
Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

4 + 6 =

Blog

PHP Magic Methods

mm

Published

on

  1. __get()/__set() – These are magic getters and setters for getting and putting values for class properties created dynamically.
  2. __isset() – This magic method will be invoked automatically while checking whether a required overloaded property is set or not.
  3. __unset() – Similarly, when we call PHP unset() function on such dynamically created properties, this magic method will automatically be invoked.
  4. __call()/__callStatic() – These two magic methods are dedicated for accessing dynamically created but invisible methods on PHP method overloading.
  5. __sleep() – This will be invoked on calling PHP serialize() function.
  6. __wakeup() – It will do the reverse work to restore objects properties and resources.
  7. __toString() – This method is expected return a string value while using class instances with PHP printing statements.
  8. __invoke()-This method defined in a class will be called when we make a function call with the name of that class instance.
  9. __set_static()-This is a static method invoked while exporting objects property array and expects such array variable as its argument.
  10. __clone()-This function is used while PHP Object Cloning.
  11. __construct()/__destruct()

Also Read :   PHP Overriding Method
Continue Reading

Trending