我正在寻找一种基于数组内容创建新数组的方法。
所以我有:
Array ( [0] => 1
[type] => first_value_i_need
[some_id] => 2
[hits] => 88
[some_other_id] => second_value_i_need
)
我想要
Array ( [0] => 1
[app_name] => "first_value_i_need-second_value_i_need"
[hits] => "88"
)
我知道我需要某种foreach函数,但我现在迷路了。
不,只要知道需要哪些键,就不需要任何循环。
$old = array(
0 => 1,
'type' => 'first_value_i_need',
'some_id' => 2,
'hits' => 88,
'some_other_id' => 'second_value_i_need'
);
$new = array(
0 => $old[0],
'app_name' => $old['type'].'-'.$old['some_other_id'],
'hits' => $old['hits'],
);
那么,基本上你想去掉app_table_id
键吗?
你可以做unset($array['app_table_id']);
如果你需要更改一些值,你可以这样做:
$array['app_name'] = $array['some_other_id'];
//>注意,我在你编辑之前发布了这个。