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

  • SEARCH
  • Home
  • 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 8453785
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:51:10+00:00 2026-06-10T11:51:10+00:00

I use javascript to send cases to and ajax function. The cases are taken

  • 0

I use javascript to send cases to and ajax function. The cases are taken from the link id. For example, if user clicked this link:
<a id="answer-yes-123">click this</a>
The javascript will split the id to 3 part, and send the middle part “yes” to ajax as a case. For most cases, when ajax receives the case, if yes do this if no do that.

switch ($case) {
    case 'yes' :
        $assignment->add();
        break;
    case 'no' :
        $assignment->remove();
        break;

There’s one exception– a numerical case. If the middle part of the link is a number, I don’t know how to make the switching statement. There are potentially unlimited different numbers, I can’t make each of them a case, How to make a condition like if(is_int($case)) to work as a case?

  • 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-06-10T11:51:11+00:00Added an answer on June 10, 2026 at 11:51 am

    In the switch default: case, you can test is_int():

    switch ($case) {
        case 'yes' :
            $assignment->add();
            break;
        case 'no' :
            $assignment->remove();
            break;
        default:
            // Determine the numeric value however you need to 
            // is_int(), is_numeric(), preg_match(), whatever...
            if (is_int($case)) {
               // numeric stuff
            }
    }
    

    This is a little strange logically, because default: is typically used for the do this if nothing else is met condition. In your case though, if you don’t need to further divide the numeric case much it works. Just be sure to comment it clearly in your code so you remember why you did it when you look back on it in six months.

    Update after comments:

    Since you already used the default:, I believe you can actually use an expression inside a case. This warrants even clearer commenting since it is not a common practice and goes kind of against the purpose of a switch:

    switch ($case) {
        case 'yes' :
            $assignment->add();
            break;
        case 'no' :
            $assignment->remove();
            break;
        // This actually works, but is highly weird. 
        // One of those things I can't believe PHP allows.
        // is_int(), is_numeric(), preg_match(), whatever... 
        case is_int($case):
            // Numeric stuff
            break;
        default:
            // default stuff
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use this Javascript code to mark threads as favourite: function fave(tid){ xmlhttp =
This php code is called through ajax from javascript and should return a numeric
Here is the javascript code I use to create the array and send it
Normally we use window.location.href=/index.php?querystring; in javascript. Is there a way to send the querystring
i use javascript to judge a page is in a iframe: if (this !=
I want use javascript setInterval function to achieve a box rotate animate effect, I
How can I use javascript to send a one way message to php? I
Currently I use the JavaScript code to send XML data in GWT. Is there
My site makes use of ajax heavily for stuff like editing user details. I
I have the following Javascript to copy the user's textarea input in this iPhone

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.