NEWS: Total Picture Views: 147066 | Total Article Views: 155647 | Top 5 Most Popular Article: 1. Am I Stuck Algorithm with Becker Robot | 2. How to read a JSON and work with it | 3. PickUpThings with Becker Robot | 4. Encrypted Data GUI (Download .Zip) | 5. Create Wall and Things with Becker

If Statement VS Switch Case Statement PHP/MySQL

Description:

In this article you will be able to see the difference between If Statement and Swtich Case Statement.

You can see the example here: https://www.jmdev.ca/sheridan/example/2/

Code:

//Assign the value;
$value = 0;


//If statement
if($value == 0){
    echo 0;
}elseif($value == 1){
    echo 1;
}elseif($value == 2){
    echo 2;
}elseif($value == 3){
    echo 3;
}elseif($value == 4){
    echo 4;
}else{
    echo "You didn't assign a number between 0 and 4";
}

echo "<br>";

//Switch Case Statement
switch($value){
    case 0:
        echo 0;
        break;
    case 1:
        echo 1;
        break;
    case 2:
        echo 2;
        break;
    case 3:
        echo 3;
        break;
    case 4:
        echo 4;
        break;
    default:
        echo "You didn't assign a number between 0 and 4";
}
Attachments: None

Tags: Switch Switch Case If elseif else

Total Views: 1001

My name is Jean-Mathieu

I created this website so other people could enjoy finding useful stuff easier. If you have any question do not hesitate to contact me.

jean8mathieuCreated on 12/19/14


affiliate_link

Disclosure: We are a website that needs compensation to operate like any other website on the internet.
We may receive consideration for our reviews but we are totally unbiased and do not accept paid reviews or fake reviews claiming to be something they are not.