Кемеровские программисты php общаются здесь
Anonymous
Фильтровать 2d-массив с помощью плоского массива белого списка
Сообщение
Anonymous » 22 ноя 2024, 09:54
У меня следующая ситуация
У меня 2 запроса
Ниже приведен массив ответов
Код: Выделить всё
Array (
[0] => Array (
[id] => 4e28258263d2c4
[answer] => Study Accounting
[question_id_fk] => 4e28258262d100
[correct] => 0
[result_text] => Thats a right answer
[order] => 1
)
[1] => Array (
[id] => 4e28258266d896
[answer] => New York
[question_id_fk] => 4e28258265b752
[correct] => 0
[score] => 0.00
[result_text] =>
[order] => 1
)
[2] => Array (
[id] => 4e282582683870
[answer] => Yes
[question_id_fk] => 4e282582674ba0
[correct] => 0
[score] => 0.00
[hot_answer] => 0
[hot_email] =>
[ordering] => 1
[result_text] =>
[order] => 1
)
[3] => Array (
[id] => 4e282582698c23
[answer] => 2
[question_id_fk] => 4e282582689e80
[correct] => 0
[score] => 0.00
[hot_answer] => 0
[hot_email] =>
[ordering] => 1
[result_text] =>
[order] => 1
)
[4] => Array (
[id] => 4e2825826af072
[answer] => 1
[question_id_fk] => 4e2825826a0371
[correct] => 0
[score] => 0.00
[hot_answer] => 0
[hot_email] =>
[ordering] => 1
[result_text] =>
[order] => 1
)
[5] => Array (
[id] => 4e2825826d9638
[answer] => NYC
[question_id_fk] => 4e2825826ca998
[correct] => 0
[score] => 0.00
[hot_answer] => 0
[hot_email] =>
[ordering] => 1
[result_text] =>
[order] => 1
)
[6] => Array (
[id] => 4e2825826d9137
[answer] => Dallas
[question_id_fk] => 4e2825826ca998
[correct] => 0
[score] => 0.00
[hot_answer] => 0
[hot_email] =>
[ordering] => 1
[result_text] =>
[order] => 1 )
)
Вот список вопросов
Код: Выделить всё
Array (
[0] => 4e28258262d100
[1] => 4e282582649464
[2] => 4e28258265b752
[3] => 4e282582674ba0
[4] => 4e282582689e80 )
foreach($questionList as $question){
// I want to Get answers in array above which
// has $question.question_id = question_id_fk . One question can have multiple
// answers
//Print Each question Id
//Print answer , result_text and correct values from all answers found from AnswerList
}
Как найти все ответы по идентификатору вопроса из массива. Мне нужно получить значения «correct» и «result_text» для ответа.
Подробнее здесь:
https://stackoverflow.com/questions/677 ... list-array
1732258447
Anonymous
У меня следующая ситуация У меня 2 запроса Ниже приведен массив ответов [code]Array ( [0] => Array ( [id] => 4e28258263d2c4 [answer] => Study Accounting [question_id_fk] => 4e28258262d100 [correct] => 0 [result_text] => Thats a right answer [order] => 1 ) [1] => Array ( [id] => 4e28258266d896 [answer] => New York [question_id_fk] => 4e28258265b752 [correct] => 0 [score] => 0.00 [result_text] => [order] => 1 ) [2] => Array ( [id] => 4e282582683870 [answer] => Yes [question_id_fk] => 4e282582674ba0 [correct] => 0 [score] => 0.00 [hot_answer] => 0 [hot_email] => [ordering] => 1 [result_text] => [order] => 1 ) [3] => Array ( [id] => 4e282582698c23 [answer] => 2 [question_id_fk] => 4e282582689e80 [correct] => 0 [score] => 0.00 [hot_answer] => 0 [hot_email] => [ordering] => 1 [result_text] => [order] => 1 ) [4] => Array ( [id] => 4e2825826af072 [answer] => 1 [question_id_fk] => 4e2825826a0371 [correct] => 0 [score] => 0.00 [hot_answer] => 0 [hot_email] => [ordering] => 1 [result_text] => [order] => 1 ) [5] => Array ( [id] => 4e2825826d9638 [answer] => NYC [question_id_fk] => 4e2825826ca998 [correct] => 0 [score] => 0.00 [hot_answer] => 0 [hot_email] => [ordering] => 1 [result_text] => [order] => 1 ) [6] => Array ( [id] => 4e2825826d9137 [answer] => Dallas [question_id_fk] => 4e2825826ca998 [correct] => 0 [score] => 0.00 [hot_answer] => 0 [hot_email] => [ordering] => 1 [result_text] => [order] => 1 ) ) [/code] Вот список вопросов [code] Array ( [0] => 4e28258262d100 [1] => 4e282582649464 [2] => 4e28258265b752 [3] => 4e282582674ba0 [4] => 4e282582689e80 ) foreach($questionList as $question){ // I want to Get answers in array above which // has $question.question_id = question_id_fk . One question can have multiple // answers //Print Each question Id //Print answer , result_text and correct values from all answers found from AnswerList } [/code] Как найти все ответы по идентификатору вопроса из массива. Мне нужно получить значения «correct» и «result_text» для ответа. Подробнее здесь: [url]https://stackoverflow.com/questions/6777241/filter-a-2d-array-by-a-flat-whitelist-array[/url]