我合并了两个数组,我得到了以下结果。
Array
(
[0] => year
[1] => Month
[2] => Array
(
[id_question] => 88
[question] => This is Question No. 1
[question_type] => 3
[answer_type] => option
[question_level] => district
[addedon] => 2017-07-23 19:15:26
)
[3] => Array
(
[id_question] => 87
[question] => This is Question No. 2
[question_type] => 3
[answer_type] => text
[question_level] => district
[addedon] => 2017-07-16 00:45:19
)
现在我想获得相同的索引并删除除了以下问题之外的所有内容
Array
(
[0] => year
[1] => Month
[2] => This is Question No. 1
[3] => This is Question No. 2
)
请帮帮我。提前致谢
答案 0 :(得分:0)
您可以尝试这种方式,但未经过测试
$expected_array=[];
foreach($your_2d_array as $k=>$v){
if(is_array($v){
$expected_array[$k] = $v['question'];
}else{
$expected_array[$k] =$v;
}
}
echo "<pre>";
print_r($expected_array);
echo "</pre>";