我有一个函数,如果值等于A,C或D,我想显示一些东西.
问题是如果值设置为B或E,则除了B或E设置外,该功能还是ACD设置中的显示数据.
我究竟做错了什么?
$linkp = opensky_featured_image_position();
if ( $linkp == 'featuredimg-1' || 'featuredimg-3' || 'featuredimg-4' ) {
echo '<h1>F - '. opensky_featured_image_position() .'</h1>';
}
if ( $linkp == 'featuredimg-2' ) {
echo '<h1>L - '. opensky_featured_image_position() .'</h1>';
}
if ( $linkp == 'featuredimg-5' ) {
echo '<h1>N - '. opensky_featured_image_position() .'</h1>';
}
Run Code Online (Sandbox Code Playgroud)
if ( $linkp == 'featuredimg-1' || 'featuredimg-3' || 'featuredimg-4' ) {
echo '<h1>F - '. opensky_featured_image_position() .'</h1>';
}
Run Code Online (Sandbox Code Playgroud)
应该
if ( $linkp == 'featuredimg-1' || $linkp == 'featuredimg-3' || $linkp == 'featuredimg-4' ) {
echo '<h1>F - '. opensky_featured_image_position() .'</h1>';
}
Run Code Online (Sandbox Code Playgroud)
如果定义了$ linkkp的所有值,你可以做这样的事情
$linkArr = array(
'featuredimg-1' => 'F',
'featuredimg-2' => 'L',
'featuredimg-3' => 'F',
'featuredimg-4' => 'F',
'featuredimg-5' => 'N',
);
$linkp = opensky_featured_image_position();
echo '<h1>'.$linkArr[$linkp].' - '. opensky_featured_image_position() .'</h1>';
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
84 次 |
| 最近记录: |