Title: Can you do a PHP style switch function?
Last modified: February 28, 2017

---

# Can you do a PHP style switch function?

 *  Resolved [sarahweb](https://wordpress.org/support/users/sarahweb/)
 * (@sarahweb)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/can-you-do-a-php-style-switch-function/)
 * Hi
 * I ma loving the plugin but I am struggling to get it to work as I need
    fieldname1
   = a checkbox yes / no fieldname2 – dependancy of the above = number 24, 40, 48,
   60 etc I would then like fieldname3 – to be linked to above if selected YES then
   24 display fieldname4 or 0 fieldname3 – to be linked to above if selected NO 
   then 24 display fieldname5 or 0 fieldname3 – to be linked to above if selected
   YES then 48 display fieldname6 or 0
 * etc
 * So I need a mixture of the IF and AND I think but its not just working out for
   me
 * AND(fieldname2>25,fieldname1=1,fieldname4,0);
 * I think I have myself mixed up with IF, AND and Javascript!
 * Any help appreciated
 * Thanks
    Sarah

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Plugin Author [codepeople](https://wordpress.org/support/users/codepeople/)
 * (@codepeople)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/can-you-do-a-php-style-switch-function/#post-8856638)
 * Hello Sarah,
 * I’m not sure to understand your equation’s description. However, there are some
   issues in the piece of code you include as reference, in javascript the operator
   for equality is the double symbol: “==” because the symbol “=” is used for assignment,
   furthermore in javascript exists the “switch” statement, similar to PHP (you 
   can find it in any javascript tutorial)
 * So, coming back to the equation, if the values associated to the choices in the
   fieldname1 are 0 and 1:
 *     ```
       (function(){
       if(fieldname1 == 1)
       {
         switch(fieldname2)
         {
           case 24: return fieldname4;
           case 48: return fieldname6;
         }
       }
       else
       {
         switch(fieldname2)
         {
           case 24: return fieldname5;
         }
       }
       return 0;
       })()
       ```
   
 * of course you should complete the cases.
    Note: I’m not including the statement“
   break” because each “case” section includes a “return” statement.
 * There are other ways to implement the equation, for example, using the “if” statement:
 *     ```
       (function(){
       if(fieldname1 == 1 && fieldname2==24) return fieldname4;
       if(fieldname1 == 1 && fieldname2==48) return fieldname6;
       if(fieldname1 == 0 && fieldname2==24) return fieldname5;
       })()
       ```
   
 * Best regards.
 *  Thread Starter [sarahweb](https://wordpress.org/support/users/sarahweb/)
 * (@sarahweb)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/can-you-do-a-php-style-switch-function/#post-8856651)
 * Thank you so very much – it all makes so much more sense when you write it like
   that!!
 *  Thread Starter [sarahweb](https://wordpress.org/support/users/sarahweb/)
 * (@sarahweb)
 * [9 years, 2 months ago](https://wordpress.org/support/topic/can-you-do-a-php-style-switch-function/#post-8857585)
 * and that helped hugely and its all working perfectly – thank you very much this
   really is exactly what I was looking for!

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Can you do a PHP style switch function?’ is closed to new replies.

 * ![](https://ps.w.org/calculated-fields-form/assets/icon-256x256.jpg?rev=1734377)
 * [Calculated Fields Form](https://wordpress.org/plugins/calculated-fields-form/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/calculated-fields-form/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/calculated-fields-form/)
 * [Active Topics](https://wordpress.org/support/plugin/calculated-fields-form/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/calculated-fields-form/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/calculated-fields-form/reviews/)

 * 3 replies
 * 2 participants
 * Last reply from: [sarahweb](https://wordpress.org/support/users/sarahweb/)
 * Last activity: [9 years, 2 months ago](https://wordpress.org/support/topic/can-you-do-a-php-style-switch-function/#post-8857585)
 * Status: resolved