What a different between switch and if while looping form on theme options

I want to know what is good practice for loop a form option in theme options.

Example I found some of coders use switch

switch $value['type']
case 'text':
...
break;
case 'select':
...
break;
case 'textarea':
...
break;
case "radio":
...
break;
case "checkbox":
...
break;

also some of them use IF

if $value['type'] = text
...
else if $value['type'] = select
...
else if $value['type'] = textarea
...
else if $value['type'] = radio
...
else if $value['type'] = checkbox
...
else

What a different between these?

Solutions

It basically boils down to readability; Switches are easier to read than a bunch of else if's.

Your question is of a general programming nature, e.g. how to write PHP and not related to theme options strictly spoken.

So unless you don't provide any wordpress related information why you ask that, I think a little read of the PHP manual is good for a starter - next to doing some basic googling.

Tags: Wordpress / Themes

Similar questions

Switch Theme Through Options Panel
Is it possible to allow users when logged in to switch the entire theme through a theme options panel? I don't want users to use the standard wordpress way, but instead just an option in their panel. Any ideas? EDIT: This is for a user on their own network site.
Implement toggle switch for theme options in settings API
I love to work with bootstrap for the forntend part of my projects, but this time I need to create a theme settings page to manage the activation of some template parts of a custom theme. I want to use a switch to enable or disable the features, but I don't know how to implement it in the wordpress way. Can anyone provide me a sample of the impleme...
Switch statement not changing CSS in a WordPress theme options page
I'm creating a theme options page for my new theme and I set up some radio buttons to change the style when a user clicks each button. After saving the changes, it is supposed to add a stylesheet to the header of the theme. It is not working correctly. I assume that my switch statement might be written incorrectly. I'm using WordPress's Settings AP...
How to add or delete default value theme options while activate and deactivate theme
I want to add & reset default value for my theme options while activate and deactivate a theme More clearly something like this Question How know is theme active or not? What a function or hook for this one. Let me know
Add active class to foundation 6 tabs while looping categories
I have a custom post type (bulletins) that I'm putting into Foundation 6.4.3's tabs and accordions. The taxonomies are the tab headings. The individual custom post type content is the accordions. My problem is on page load, no tabs appear. I need to add 'is-active' class to the first class="tabs-panel" on the page, but I can't figure the best way t...
Increase offset while looping
I'm writing a custom post plugin which is displaying the custom posts in groups as tabs. For each group 4 post. Is it possible to write a query with offset which will increase with every loop? So the result would be: - first query displays posts from 1 to 4 - second query displays posts from 5 to 8 - third query displays post from 9 to 12 etc. UPDA...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.