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>';
}