Closed. This question is off-topic. It is not currently accepting answers.admin管理员组文章数量:1336113
Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 7 years ago.
Improve this questionFirstly sorry for my English. I hope you understand me.
I have an array like this:
$fields = array(
'author' => '<div class="form-group"><input class="form-control" id="author" name="author" type="text" placeholder="Name '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' /></div>',
'email' => '<div class="form-group"><input class="form-control" id="email" name="email" type="text" placeholder="E-mail '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
'url' => '<div class="form-group"><input class="form-control" id="url" name="url" type="text" placeholder="Website '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"' . $aria_req . ' /></div>',
);
I want the use if statement inside this array. Like this:
$fields = array(
'author' => '<div class="form-group"><input class="form-control" id="author" name="author" type="text" placeholder="Name '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' /></div>',
'email' => '<div class="form-group"><input class="form-control" id="email" name="email" type="text" placeholder="E-mail '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
if($showURL==1){'url' => '<div class="form-group"><input class="form-control" id="url" name="url" type="text" placeholder="Website '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"' . $aria_req . ' /></div>'},
);
I'm trying this but it is shows a syntax error:
$fields = array(
'author' => '<div class="form-group"><input class="form-control" id="author" name="author" type="text" placeholder="Adınız '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' /></div>',
'email' => '<div class="form-group"><input class="form-control" id="email" name="email" type="text" placeholder="E-posta adresiniz '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
(($showURL==1) ? 'url' => '<div class="form-group"><input class="form-control" id="url" name="url" type="text" placeholder="Website '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"' . $aria_req . ' /></div>' : '' ) ,
);
I'm getting this error: Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in C:\wamp\www\blabla\comments.php on line 62
How can I use this if statement inside this array? Anybody can help me?
Closed. This question is off-topic. It is not currently accepting answers.Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.
Closed 7 years ago.
Improve this questionFirstly sorry for my English. I hope you understand me.
I have an array like this:
$fields = array(
'author' => '<div class="form-group"><input class="form-control" id="author" name="author" type="text" placeholder="Name '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' /></div>',
'email' => '<div class="form-group"><input class="form-control" id="email" name="email" type="text" placeholder="E-mail '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
'url' => '<div class="form-group"><input class="form-control" id="url" name="url" type="text" placeholder="Website '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"' . $aria_req . ' /></div>',
);
I want the use if statement inside this array. Like this:
$fields = array(
'author' => '<div class="form-group"><input class="form-control" id="author" name="author" type="text" placeholder="Name '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' /></div>',
'email' => '<div class="form-group"><input class="form-control" id="email" name="email" type="text" placeholder="E-mail '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
if($showURL==1){'url' => '<div class="form-group"><input class="form-control" id="url" name="url" type="text" placeholder="Website '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"' . $aria_req . ' /></div>'},
);
I'm trying this but it is shows a syntax error:
$fields = array(
'author' => '<div class="form-group"><input class="form-control" id="author" name="author" type="text" placeholder="Adınız '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' /></div>',
'email' => '<div class="form-group"><input class="form-control" id="email" name="email" type="text" placeholder="E-posta adresiniz '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
(($showURL==1) ? 'url' => '<div class="form-group"><input class="form-control" id="url" name="url" type="text" placeholder="Website '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"' . $aria_req . ' /></div>' : '' ) ,
);
I'm getting this error: Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in C:\wamp\www\blabla\comments.php on line 62
How can I use this if statement inside this array? Anybody can help me?
Share Improve this question edited May 25, 2020 at 13:40 Faruk asked Oct 28, 2017 at 19:41 FarukFaruk 2510 bronze badges1 Answer
Reset to default 2Try this Omer
$fields = array(
'author' => '<div class="form-group"><input class="form-control" id="author" name="author" type="text" placeholder="Name '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author'] ) . '" ' . $aria_req . ' /></div>',
'email' => '<div class="form-group"><input class="form-control" id="email" name="email" type="text" placeholder="E-mail '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30"' . $aria_req . ' /></div>',
);
if($showURL == 1) {
$fields['url'] = '<div class="form-group"><input class="form-control" id="url" name="url" type="text" placeholder="Website '.( $req ? '*' : '' ) .'" value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30"' . $aria_req . ' /></div>';
}
本文标签: phpHow to use if statement in an array
版权声明:本文标题:php - How to use if statement in an array? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742402926a2468244.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论