我有一个名为$question_data
的数组,其中有一个名为['question_text']的键,它包含一些HTML标记也存在的字符串。现在要清除这些问题,我正在对这个数组的每个元素应用一个名为clear_data()的函数。但是我希望在清理数据之后恢复数组。意味着所有元素的其他键和值应该是完整的,只有key ['question_text']的数据才能清楚。请问有人可以在这方面帮助我吗?我的数组如下:
Array
(
[question_id] => 24803
[question_parent_id] => 0
[question_subject_id] => 7
[question_topic_id] => 272
[question_directions] =>
[question_text] => Vitamin <i>B<sub>12</sub></i><sub> </sub>contains metal
[question_file] =>
[question_description] =>
[question_difficulty_type] => 2
[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] => 1326877035
[question_updated_staff_id] => bf1eda9e6f47ede5fedac85e1016e2d1
[question_updated_date] => 1338547782
)
答案 0 :(得分:0)
你可以这样做。
foreach ($question_data as $k => $v) {
if ($k === 'question_text') {
$question_data[$k] = cleardata($v);
}
}
答案 1 :(得分:0)
function clear_data( &$qd) {
$qd['question_text']= '';
// or unset($qd['question_text']); to remove it totally
}
clear_data( $question_data);