How to make this PHP if statement more simple and shorter? -
i have feeling next code can shortened have no thought how rewrite :)
$post_type = isset( $_get['post_type'] ) ? $_get['post_type'] : ''; if( $post_type == 'faq' && !isset( $_request['mode'] ) ) $_request['mode'] = 'excerpt'; // if go else... doesn't work elseif( $post_type !== 'faq' && !isset( $_request['mode'] ) ) $_request['mode'] = 'list';
update
as can see, !isset( $_request['mode'] )
used twice. $post_type == 'faq'
used twice, in elseif i'm checking negative.
seriously there no way rewrite 1 if
without else
...?
how using ternary operator testing 'faq' ?
$post_type = isset( $_get['post_type'] ) ? $_get['post_type'] : ''; if (!isset( $_request['mode'] )) { $_request['mode'] = ($post_type == 'faq') ? 'excerpt' : 'list'; }
php if-statement
No comments:
Post a Comment