How PHP modifies array key names

Source: Internet
Author: User
How does PHP modify the array key name? This article mainly introduces the method of PHP to modify the array key name, involving PHP for the traversal of the array, interception, conversion and other related operations skills, the need for friends can refer to. We hope to help you.

This article describes how PHP modifies the array key names. Share to everyone for your reference, as follows:

$ar = Array (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 '), array (1 = ' C ', 2 = 3, 4 = ' quit ', 5 = ' QQQ ', 6 = ' xxx ', 7 = ' CCC '), $kname = Array (' StaffID ', ' wage ', ' Na Me ', ' work ', ' Type '), function foo (& $v, $k, $kname) {$v = Array_combine ($kname, Array_slice ($v, 1,-1));} Array_walk ($ar, ' foo ', $kname);p Rint_r ($ar);

The result of the operation is:

Array (  [0] = = Array    (      [StaffID] = [      wage] = [      Name] = = Long      [work] = zzz< C6/>[type] = KKK    )  [1] = =    Array      ([StaffID] [      wage] = [      Name] = King      [Work] = LLL      [Type] = TTT    )  [2] = =    Array      ([StaffID] = [      wage] = [      Name] = + quit< C21/>[work] = QQQ      [Type] = xxx    ))

Related recommendations:

Summary of PHP array sorting methods

Ways to convert PHP arrays to and from strings

PHP array traversal foreach syntax structure and examples

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.