开发者

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 开发者_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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜