Home >Backend Development >PHP Tutorial >How should I write the application logic in PHP?

How should I write the application logic in PHP?

WBOY
WBOYOriginal
2016-08-04 09:22:261080browse

I have a function that can return which devices are currently available. The devices are as follows

<code>$page_style_default = array('pc','mobile','weixin','pad','pc_old','mobile_old','pc_soft','mobile_soft');</code>

Then I have a function that determines which devices are currently available.

For example, the currently available equipment is

<code>array('pc','pad');</code>

The requirement is that when it is determined that the current device is mobile, if mobile does not exist, then it is determined that pad exists, and then pad is called

If it is judged that the current device is mobile_old, and the only options are (pc and pad), first judge that mobile_old exists, then judge that mobile exists, and then judge that pad exists. If there is no pad, the final output is pc

If writing if statements feels too much, I don’t know what is the best way?

The hierarchical relationship is as follows

https://www.processon.com/view/577c5bafe4b04bc7eeac5bae

Reply content:

I have a function that can return which devices are currently available. The devices are as follows

<code>$page_style_default = array('pc','mobile','weixin','pad','pc_old','mobile_old','pc_soft','mobile_soft');</code>

Then I have a function that determines which devices are currently available.

For example, the currently available equipment is

<code>array('pc','pad');</code>

The requirement is that when it is determined that the current device is mobile, if mobile does not exist, then it is determined that pad exists, and then pad is called

If it is judged that the current device is mobile_old, and then the only options are (pc and pad), first judge that mobile_old exists, then judge that mobile exists, and then judge that pad exists. If there is no pad, the final output is pc

If writing if statements feels too much, I don’t know what is the best way?

The hierarchical relationship is as follows

https://www.processon.com/view/577c5bafe4b04bc7eeac5bae

Solved,
Save pc and mobile in separate arrays, and then use in_array() to determine when the current device exists and whether the current device belongs to pc or mobile, and finally perform unified output.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn