Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3611862
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T21:55:40+00:00 2026-05-18T21:55:40+00:00

The example below is an extráct from http://php.net/manual/de/control-structures.switch.php <?php $totaltime = 0; switch ($totaltime)

  • 0

The example below is an extráct from http://php.net/manual/de/control-structures.switch.php

<?php
$totaltime = 0;
switch ($totaltime) {

    case ($totaltime < 1):
        echo "That was fast!";
        break;

    case ($totaltime > 1):
        echo "Not fast!";
        break;

    case ($totaltime > 10):
        echo "That's slooooow";
        break;
}

?>

I expected the result as “That was fast.” But actual result is “Not fast!”. It would be great if some one can explain me why?

But if i add another case, case 0: echo "That was super fast!". Then it is echoing properly. i.e “That was super fast!”. Please help me how to use conditional switch statement.

EDIT:-

Thanks all for your responses. I am able to overcome the above problem by modifyong switch($totaltime) to switch(1)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T21:55:41+00:00Added an answer on May 18, 2026 at 9:55 pm

    case ($totaltime < 1): means 1 to PHP (that equation returns true)

    case ($totaltime > 1): means 0 to PHP (that equation returns false)

    Since $totaltime is 0, you get that output

    In other words PHP compares $totaltime to the result of the comparisons.

    EDIT regarding EDIT in OP:

    You need to get rid of the switch()-statement. You only use it to easily compare against different values and not use additional expressions with it.

    I mean what is wrong with

    <?php
    $totaltime = 0;
    
    if ($totaltime < 1) {
        echo "That was fast!";
    } else if ($totaltime > 10) {
        echo "That's slooooow";
    } else if ($totaltime > 1) {
        echo "Not fast!";
    }
    
    ?>
    

    EDIT: please note that I switched the last two if-statements to make it really work.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got the code below from a tutorial that teaches how to make wordpress
Hi there's a live version of the code below (taken from a tutorial) at
I'm installing Satchmo following these instructions: http://forum.webfaction.com/viewtopic.php?pid=10579#p10579 When I want to check my installation,
I'm trying to do some simple jQuery stuff 'dynamically' from within a MediaWiki content
I tried transferring a working login system from one domain to another. It works
I have a php program i have developed on the internet. So far i
<?php wp_nav_menu(); ?> So I want to use the above function to spit out
I followed the wiki artichle (http://codeigniter.com/wiki/gchart/revision/5312/) to practice google chart in my CI 2.0.
I am new to Codeigniter, and I have trouble with the pagination class. From
I am sending an AJAX request using javascript to a servlet. The servlet is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.