How to change the key name of a PHP two-dimensional array
I get an array of the following in the code:
1234567 (Key Name)
-----------------------------------
A5060longzzzkkkooo
B6070kingllltttppp
C7080quitqqqxxxccc
------------------------------------
I want to take out 2,3,4,5,6 this five column to create a new array, and the new array with the string as the key name
As follows:
Staffidwagenameworktype
-----------------------------
5060longzzzkkk
6070kinglllttt
7080quitqqqxxx
-----------------------------
What's the best way to ask? Beginner PHP, the two-dimensional array is not very understanding, ask you.
------Solution--------------------
Var_export the array out. I don't understand what structure your array is.
------Solution--------------------
Array_slice ($arr, 1,-1), intercept and change the key name.
------Solution--------------------
A complete notation
PHP Code
$ar = Array (Array (1 = ' a ', 2 = 3, 4 = ' long ', 5 = ' zzz ', 6 = ' kkk ', 7 = ' ooo '), array (1 = ' B ', 2 =, 3 =, 4 = ' King ', 5 = ' lll ', 6 = ' TTT ') , 7 = ' PPP '), array (1 = ' C ', 2 = 3, 4 = ' quit ', 5 = ' QQQ ', 6 = ' xxx ', 7 = ' CCC ') ,); $kname = Array (' StaffID ', ' wage ', ' Name ', ' work ', ' Type '), function foo (& $v, $k, $kname) {$v = Array_combine ($knam E, Array_slice ($v, 1,-1));} Array_walk ($ar, ' foo ', $kname);p Rint_r ($ar);
------Solution--------------------
to discuss
Complete syntax for PHP code
$ar = Array ( br> Array (1 = ' a ', 2 =, 3 =, 4 = ' long ', 5 = ' zzz ', 6 = ' kkk ', 7 = ' ooo '),
Arra
Y (1 = ' B ', 2 =, 3 =, 4 = ' King ', 5 = ' lll ', 6 = ' TTT ', 7 = ' PPP '),......