Я новичок в сложных массивах в PHP. У меня есть ассоциативный массив с именем $questions следующим образом (для справки я печатаю только первые два элемента этого ассоциативного массива, фактический массив слишком велик):
Array
(
[0] => Array
(
[question_id] => 33185
[question_parent_id] => 0
[question_subject_id] => 4
[question_topic_id] => 503
[question_directions] =>
[question_text] => Two gases are at 300 K and 350 K respectively Ratio of average kinetic energy of their molecules is
[question_file] =>
[question_description] =>
[question_difficulty_type] => 1
[question_has_sub_ques] => 0
[question_picked_individually] => no
[question_appeared_count] => 0
[question_manual] => 0
[question_site_id] =>
[question_created_staff_id] => fbfee12504bf3c4a038d4c9f142f894e
[question_added_date] => 1328180210
[question_updated_staff_id] =>
[question_updated_date] => 0
)
[1] => Array
(
[question_id] => 33187
[question_parent_id] => 0
[question_subject_id] => 4
[question_topic_id] => 503
[question_directions] =>
[question_text] => what will be the temperature when the rms velocity is double the rms velocity at 300 K
[question_file] =>
[question_description] =>
[question_difficulty_type] => 1
[question_has_sub_ques] => 0
[question_picked_individually] => no
[question_appeared_count] => 0
[question_manual] => 0
[question_site_id] =>
[question_created_staff_id] => fbfee12504bf3c4a038d4c9f142f894e
[question_added_date] => 1328180274
[question_updated_staff_id] =>
[question_updated_date] => 0
)
)
Теперь мой код манипуляции с этим массивом выглядит следующим образом:
/*Compare each question with all the questions present within an array*/
foreach ($questions as $outer_data) {
$outer_question = $outer_data['question_text'];
foreach ($questions as $inner_data) {
$inner_question = $inner_data['question_text'];
$same_chars = similar_text($outer_question, $inner_question, $percent);
$percentage = number_format((float)$percent, 2, '.', '');
if($percentage > 50) {
//I'm not able to write a perfect code to create an array here, please help me out in writing this code
}
}
}
В приведенном выше коде я написал комментарий там, где столкнулся с проблемой. На самом деле я хочу прикрепить все идентификаторы вопросов к исходному массиву $questions, когда условие (т.е. $percentage > 50) будет выполнено. Предположим, что для вопроса с идентификатором 33185 следующие идентификаторы имеют похожие вопросы, тогда элемент массива, имеющий значение question_id как 33185, должен выглядеть следующим образом:
Array
(
[0] => Array
(
[question_id] => 33185
[question_parent_id] => 0
[question_subject_id] => 4
[question_topic_id] => 503
[question_directions] =>
[question_text] => Two gases are at 300 K and 350 K respectively Ratio of average kinetic energy of their molecules is
[question_file] =>
[question_description] =>
[question_difficulty_type] => 1
[question_has_sub_ques] => 0
[question_picked_individually] => no
[question_appeared_count] => 0
[question_manual] => 0
[question_site_id] =>
[question_created_staff_id] => fbfee12504bf3c4a038d4c9f142f894e
[question_added_date] => 1328180210
[question_updated_staff_id] =>
[question_updated_date] => 0
[similar_questions_ids] => Array
(
[0] => 60905
[1] => 60929
[2] => 60912
)
)
)
Теперь я столкнулся с проблемой написания идеального кода для желаемого результата. Если я написал этот код неправильно, вы можете импровизировать, так как я новичок в массивах в PHP. Любые предложения будут приветствоваться. Может ли кто-нибудь помочь мне в этом отношении, пожалуйста? Любая помощь будет высоко оценен.