php 替换二维数组中的 key
// 需要替换 key 的数组 $arr_old = array( ‘0‘ => array(‘id‘ => 1, ‘name‘ => ‘Carroll‘), ‘1‘ => array(‘id‘ => 2, ‘name‘ => ‘Chrdai‘), ‘3‘ => array(‘id‘ => 3, ‘name‘ => ‘xiaodai‘), ); // 将新的key定义一个新数组 $key_name = array(‘key1‘,‘key2‘,‘key3‘); // 现在开始替换 $arr_new = array_combine($key_name,$arr_old); var_dump($arr_new); /* array (size=3) ‘key1‘ => array (size=2) ‘id‘ => int 1 ‘name‘ => string ‘Carroll‘ (length=7) ‘key2‘ => array (size=2) ‘id‘ => int 2 ‘name‘ => string ‘Chrdai‘ (length=6) ‘key3‘ => array (size=2) ‘id‘ => int 3 ‘name‘ => string ‘xiaodai‘ (length=7) */
此文为我工作中的总结,如有转载,请注明出处:http://www.cnblogs.com/chrdai/p/7219107.html
时间: 2024-11-01 14:40:14