【发布时间】:2013-11-25 10:33:54
【问题描述】:
我有一个名为 $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
)
[2] => Array
(
[question_id] => 33188
[question_parent_id] => 0
[question_subject_id] => 4
[question_topic_id] => 503
[question_directions] =>
[question_text] => a gas at 300 K has pressure 4 × 10-10 N/m 2 If k = 1.38 × 10-23 J/K the number of molecules./ cm3 of the order of
[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] => 1328180400
[question_updated_staff_id] => 1096ab29ecde5cec198bb2ebe730d229
[question_updated_date] => 1338272917
)
[3] => Array
(
[question_id] => 33190
[question_parent_id] => 0
[question_subject_id] => 4
[question_topic_id] => 503
[question_directions] =>
[question_text] => The rms speed of oxygen molecules at a certain temperature is v if the temperature is doubled and the oxygen gas dissociates into atomic oxygen, the rms speed would be
[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] => 1328180486
[question_updated_staff_id] => 1096ab29ecde5cec198bb2ebe730d229
[question_updated_date] => 1338273032
)
)
我有另一个名为 $excluding_this 的数组。打印此数组后,我们得到以下输出:
Array ( [0] => a [1] => at [2] => is [3] => are [4] => when [5] => whom )
现在我要做的是,我必须解析数组$questions 的每个数组元素并访问包含在键['question_text'] 中的字符串。
在这个字符串中,我必须检查数组$excluding_this 中的任何字符串是否存在于字符串中(['question_text'] 键中包含的字符串)。
如果['question_text'] 值中存在任何或所有字符串,则从键['question_text'] 的值中删除所有这些字符串,并且应该返回具有这些更改的['question_text'] 的新数组。
我不知道我应该如何以最佳方式实现这一目标。有人可以帮我解决这个问题吗?
任何形式的帮助将不胜感激。等待您的回复。
【问题讨论】:
标签: php arrays string associative-array key-value