开发者

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

开发者 https://www.devze.com 2023-02-09 06:04 出处:网络
I want to know what is good practice for loop a form option in theme options. Example I found some of coders use switch

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 开发者_Python百科$value['type'] = radio
...
else if $value['type'] = checkbox
...
else

What a different between these?


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消