Home >Backend Development >PHP Tutorial >PHP handles array key value changes
The content of this article is about PHP processing array key value changes. It has certain reference value. Now I share it with everyone. Friends in need can refer to it
$data =array( 'classname' =>' 我们不一样', 'id' => ' 6666', ); //更改 id key值为cate_id $datas =array( 'classname' =>$data['classname'], 'cate_id' =>$data['id'], ); $arr3 =array_combine(array_keys($datas),$data); echo '<pre class="brush:php;toolbar:false">'; var_dump($arr3); echo '';
After printing, it will be
array(2) { ["classname"]=> string(16) " 我们不一样" ["cate_id"]=> string(5) " 6666" }
$data =array( 'classname' =>' 我们不一样', 'id' => ' 6666', ); //更改 id key值为cate_id foreach ($data as $v=>$k){ $data['cate_id'] =$data['id']; //key字段赋值 } unset($data['id']); //销毁原字段id key dump($data);die;I don’t know if there is a simple method Related recommendations:
php Example code for handling conversion between arrays and XML
The above is the detailed content of PHP handles array key value changes. For more information, please follow other related articles on the PHP Chinese website!