으로 삼항 연산자를 포함 할 수 없습니다 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
문장과 동일하지만, 삼항로 제작 있도록
echo " <a class=\"pagination-link\" href='{$_SERVER['PATH_INFO']}?page=$nextpage . ($paginationAddCommentAnchor ?? null) ? '#comment-target' : null'> > </a> ";
은 무엇 적절한 구문 것입니까?
'$ 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)를 사용하여 그 값을 주변 문자열과 연결해야합니다. /nlanguage.operators.string.php) – axiac