이 같은 foreach 루프가이동하기 전에 값을 검사하는 foreach 루프가 변경되었습니다.
<?php $current_question = "";
foreach ($question_and_answers as $qa) : ?>
<?php $current_question == $qa['current_question']; ?>
<?php if($current_question == $current_question) : ?>
<input type="text" name="question[]" value="<?php echo $qa['question']; ?>"/>
<?php endif; ?>
<?php endforeach; ?>
입력 필드를 만들 때마다 루프가 새로운 질문에 안타를 쳤습니다. (질문은 많은 답변을 가질 수 있습니다. . 내가 한 것은 효과가없는 것 같습니다.
Array
(
[0] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 5
[answer] => Simon
[questions_question_id] => 2
[correct] => true
)
[1] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 6
[answer] => Dave
[questions_question_id] => 2
[correct] => false
)
[2] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 7
[answer] => Fred
[questions_question_id] => 2
[correct] => false
)
[3] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 8
[answer] => John
[questions_question_id] => 2
[correct] => false
)
[4] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 9
[answer] => Crawford
[questions_question_id] => 3
[correct] => true
)
[5] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 10
[answer] => Caine
[questions_question_id] => 3
[correct] => false
)
[6] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 11
[answer] => Rooney
[questions_question_id] => 3
[correct] => false
)
[7] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 12
[answer] => Ainley
[questions_question_id] => 3
[correct] => false
)
[8] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 13
[answer] => Blue
[questions_question_id] => 4
[correct] => true
)
[9] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 14
[answer] => Yellow
[questions_question_id] => 4
[correct] => false
)
[10] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 15
[answer] => Green
[questions_question_id] => 4
[correct] => false
)
[11] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 16
[answer] => Red
[questions_question_id] => 4
[correct] => false
)
[12] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 17
[answer] => Huddersfield Town
[questions_question_id] => 5
[correct] => true
)
[13] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 18
[answer] => Leeds United
[questions_question_id] => 5
[correct] => false
)
[14] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 19
[answer] => Manchester United
[questions_question_id] => 5
[correct] => false
)
[15] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 20
[answer] => Wolverhampton Wanderes
[questions_question_id] => 5
[correct] => false
)
)
Array
(
[0] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 5
[answer] => Simon
[questions_question_id] => 2
[correct] => true
)
[1] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 6
[answer] => Dave
[questions_question_id] => 2
[correct] => false
)
[2] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 7
[answer] => Fred
[questions_question_id] => 2
[correct] => false
)
[3] => Array
(
[question_id] => 2
[question] => What is my name?
[tests_test_id] => 2
[answer_id] => 8
[answer] => John
[questions_question_id] => 2
[correct] => false
)
[4] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 9
[answer] => Crawford
[questions_question_id] => 3
[correct] => true
)
[5] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 10
[answer] => Caine
[questions_question_id] => 3
[correct] => false
)
[6] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 11
[answer] => Rooney
[questions_question_id] => 3
[correct] => false
)
[7] => Array
(
[question_id] => 3
[question] => What is my surname?
[tests_test_id] => 2
[answer_id] => 12
[answer] => Ainley
[questions_question_id] => 3
[correct] => false
)
[8] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 13
[answer] => Blue
[questions_question_id] => 4
[correct] => true
)
[9] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 14
[answer] => Yellow
[questions_question_id] => 4
[correct] => false
)
[10] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 15
[answer] => Green
[questions_question_id] => 4
[correct] => false
)
[11] => Array
(
[question_id] => 4
[question] => What is my favourite colour?
[tests_test_id] => 2
[answer_id] => 16
[answer] => Red
[questions_question_id] => 4
[correct] => false
)
[12] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 17
[answer] => Huddersfield Town
[questions_question_id] => 5
[correct] => true
)
[13] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 18
[answer] => Leeds United
[questions_question_id] => 5
[correct] => false
)
[14] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 19
[answer] => Manchester United
[questions_question_id] => 5
[correct] => false
)
[15] => Array
(
[question_id] => 5
[question] => Who do I support?
[tests_test_id] => 2
[answer_id] => 20
[answer] => Wolverhampton Wanderes
[questions_question_id] => 5
[correct] => false
)
)
배열을 반복하면서 배열을 반복하려고 할 때마다 새 질문을 만날 때마다 값이있는 텍스트 입력이 필요합니다. 문제의
'작동하지 않는 것 같습니다. '는 문제 설명이 아닙니다. – Bobby