PHP switch statement returns invalid output

0 votes

The PHP switch statement returns invalid output :

$cond = "Night";

switch($cond){
    case "Morning":
    case "Night":
        $name = "Good";

    case "Morning" :
        echo $name." Morning";
        break;

    case "Night" :
        echo $name." Night";
        break;
}

Output: Good Morning

Expected: Good Night

Can someone help me with this?

Jun 9, 2022 in PHP by Kichu
• 19,040 points
349 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In PHP

0 votes
1 answer

How to include a PHP variable inside a MySQL statement?

Hii, You can try this: $query="SELECT * FROM CountryInfo ...READ MORE

answered Apr 9, 2020 in PHP by Niroj
• 82,840 points
17,000 views
0 votes
1 answer

Invalid argument supplied for foreach() on line 25. Error in my php and mysql

Hello @viven , This should be a simple fix ...READ MORE

answered Aug 4, 2020 in PHP by Niroj
• 82,840 points
4,312 views
0 votes
1 answer

Error:Cannot modify header information - headers already sent by (output started at /some/file.php:12) in /some/file.php on line 23

Hello @kartik, This error message gets triggered when anything is ...READ MORE

answered Sep 16, 2020 in PHP by Niroj
• 82,840 points
5,685 views
0 votes
1 answer

How to run process with realtime output in PHP?

Hello @kartik, This worked for me: $cmd = "ping ...READ MORE

answered Oct 20, 2020 in PHP by Niroj
• 82,840 points
4,147 views
0 votes
1 answer

How do I capture PHP output into a variable?

Hello, Try this: <?php ob_start(); ?> <xml/> <?php $xml = ob_get_clean(); ...READ MORE

answered Nov 3, 2020 in PHP by Niroj
• 82,840 points
1,149 views
0 votes
1 answer

Php exec() not returning error message in output

Hello @kartik, You need to capture the stderr too. Redirecting stderr to stdout should do ...READ MORE

answered Nov 18, 2020 in PHP by Niroj
• 82,840 points
5,099 views
+1 vote
2 answers

Scp Php files into server using gradle

Tru something like this: plugins { id ...READ MORE

answered Oct 11, 2018 in DevOps & Agile by lina
• 8,220 points
1,567 views
0 votes
1 answer

How do I create folder under an Amazon S3 bucket through PHP API?

Of Course, it is possible to create ...READ MORE

answered Apr 24, 2018 in AWS by anonymous
11,409 views
0 votes
1 answer

Failure uploading Image on AmazonS3 with PHP SDK

Try this, I took it out from ...READ MORE

answered May 4, 2018 in AWS by Cloud gunner
• 4,670 points
4,456 views
0 votes
1 answer

Trying to call AWS API via PHP

Try using AWS SDK for PHP, Link ...READ MORE

answered Jun 6, 2018 in AWS by Cloud gunner
• 4,670 points
1,750 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP