I am looking for a way to create a new array based on array contents.
so i've got:
Array ( [0] => 1
[type] => first_value_i_need
[some_id] => 2
[hits] => 88
[some_other_id] => second_value_i_need
)
and i would like to get
Array ( [0] => 1
[app_name] =&开发者_JAVA技巧gt; "first_value_i_need-second_value_i_need"
[hits] => "88"
)
I know that i need some sort of foreach function, but i'm right now lost.
No, you don't need any loops as long as you know which keys you need.
$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'],
);
So basically do you wnat to get rid of the app_table_id
key ?
You can do unset($array['app_table_id']);
And if you need to change some value you can do :
$array['app_name'] = $array['some_other_id'];
//> Note i posted this before your edit.
精彩评论