Connect with us

PHP

PHP Switch

mm

Published

on

The switch is used to execute dissimilar actions based on dissimilar conditions.
Syntax:-
switch (n) {
case label1:
Execution code if n=label1;
break;
case label2:
Execution code if n=label2;
break;
case label3:
Execution code if n=label3;
break;

default:
Execution code if n is different from all labels;
}
Example:-
<?php
$week = “monday”;

switch ($week) {
case “sunday”:
echo “Today is Sunday!”;
break;
case “Monday”:
echo “Today is monday!”;
break;
case “Tuesday”:
echo “today is Tuesday!”;
break;
default:
echo ” Today is Wednesday!”;
}
?>

Also Read :   Where do I hire PHP developers in India?

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 *

5 × four =

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 Constants
Continue Reading

Trending