How to change the key name of a PHP two-dimensional array

Source: Internet
Author: User
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 '),......
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.