How to modify the key name of a two-dimensional array in php: first extract the array [var_export]; then use the array to intercept it and then change the key name. The code is [array_slice($arr,1,-1);].
php method to modify the key name of a two-dimensional array:
Export the array var_export.
array_slice($arr,1,-1); intercept it and change the key name
Complete writing method
PHP code $ar = array( array(1 => 'a', 2 => 50, 3 => 60, 4 => 'long', 5 => 'zzz', 6 => 'kkk', 7 => 'ooo'), array(1 => 'b', 2 => 60, 3 => 70, 4 => 'king', 5 => 'lll', 6 => 'ttt', 7 => 'ppp'), array(1 => 'c', 2 => 70, 3 => 80, 4 => 'quit', 5 => 'qqq', 6 => 'xxx', 7 => 'ccc'), ); $kname = array('StaffId', 'Wage', 'Name', 'Work', 'Type'); function foo(&$v, $k, $kname) { $v = array_combine($kname, array_slice($v, 1, -1)); } array_walk($ar, 'foo', $kname); print_r($ar);
If you want to learn more about programming, please Please pay attention to the php training column!
The above is the detailed content of How to modify the key name of a two-dimensional array in php. For more information, please follow other related articles on the PHP Chinese website!