단순 문법 문의합니다. 채택완료
Copy
$manage_item = "<a href='remove_punishment'('{$list[$i]['mp_id']}', '{$list[$i]['mb_id']}', '{$list[$i]['register_date']}', '{$type_label}')'><u>삭제</u></a>";
위와 같은 html/php 코드가 있는데요. 이 라인이 문법에 맞는건가요?
따움표라던지 괄호등이 문법에 맞는건지 궁금합니다.
답변 3개
채택된 답변
+20 포인트
1년 전
PHP 문법은 문제없는 올바른 문법입니다.
다음처럼 의존 데이터를 임의로 만들고
Copy
$list = [
['mp_id' => 'mp_id_1', 'mb_id' => 'mb_id_1', 'register_date' => '2024-02-09'],
['mp_id' => 'mp_id_2', 'mb_id' => 'mb_id_2', 'register_date' => '2024-02-08'],
];
$type_label = 'type_label_value';
출력 확인을 해볼수 있습니다.
Copy
for ($i = 0, $i_cnt = count($list); $i < $i_cnt; $i++) {
$manage_item = "<a href='remove_punishment'('{$list[$i]['mp_id']}', '{$list[$i]['mb_id']}', '{$list[$i]['register_date']}', '{$type_label}')'><u>삭제</u></a>";
echo $manage_item . PHP_EOL;
}
다만 출력되는 결과의 웹브라우저 실행인 경우 정상동작을 위해
다음처럼 수정해볼수 있습니다.
Copy
for ($i = 0, $i_cnt = count($list); $i < $i_cnt; $i++) {
$manage_item = '<a href="javascript:remove_punishment(\'' . $list[$i]['mp_id'] . '\', \'' . $list[$i]['mb_id'] . '\', \'' . $list[$i]['register_date'] . '\', \'' . $type_label . '\')"><u>삭제</u></a>';
echo $manage_item . PHP_EOL;
}
echo '<script>function remove_punishment(a,b,c,d) { alert(Array.from(arguments).join(",")); }</script>';
또는 PHP Heredoc 문법으로 조금 더 편하게 표현할수 있습니다.
Copy
for ($i = 0, $i_cnt = count($list); $i < $i_cnt; $i++) {
$manage_item = <<<HEREDOC
<a href="javascript:remove_punishment('{$list[$i]['mp_id']}', '{$list[$i]['mb_id']}', '{$list[$i]['register_date']}', '{$type_label}')"><u>삭제</u></a>
HEREDOC;
echo $manage_item . PHP_EOL;
}
echo '<script>function remove_punishment(a,b,c,d) { alert(Array.from(arguments).join(",")); }</script>';
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
댓글을 작성하려면 로그인이 필요합니다.
eyekiss
1년 전
Copy
$manage_item = "<a href='".remove_punishment('{$list[$i]['mp_id']}', '{$list[$i]['mb_id']}', '{$list[$i]['register_date']}', '{$type_label}')."'><u>삭제</u></a>";
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인