を三項演算子を埋め込むことはできませんecho
文です:は、ここでecho文に
echo " <a class=\"pagination-link\" href='{$_SERVER['PATH_INFO']}?page=$nextpage#comment-target'> > </a> ";
そして、ここではternary expression
です。何それがないと、条件がtrueの場合にのみ、リンクの最後に#comment-target
を連結です:
($paginationAddCommentAnchor ?? null) ? '#comment-target' : null
私はternary expression
によってecho
声明、#comment-target
に交換する必要がありますが、すべての試みは醜いボールのように終わります間違った見積もりで泥の例の試み:適切な構文になり何
echo " <a class=\"pagination-link\" href='{$_SERVER['PATH_INFO']}?page=$nextpage . ($paginationAddCommentAnchor ?? null) ? '#comment-target' : null'> > </a> ";
ので、最終的な結果は、初期echo
文と同じですが、三成分を用いて製造さ?
'$ paginationAddCommentAnchor ?? null'は '$ paginationAddCommentAnchor'と同じです – axiac
複数の行と変数を使用すると、コードを読みやすくなります。 – Quentin
PHPは、二重引用符( '" ')で囲まれた文字列内の[variables parsing](http://php.net/manual/en/language.types.string.php#language.types.string.parsing)あなたが式を評価する必要があるならば、それを文字列の外に置き、[文字列連結演算子( '.')](http://php.net/manual/en)を使ってその値を周囲の文字列に連結しなければなりません/ @ language.operators.string.php)。 – axiac