PHP modified array Key Name instance detailed

Source: Internet
Author: User
This article mainly introduces PHP to modify the array key name method, involving PHP for array traversal, interception, conversion and other related operations skills, the need for friends can refer to the following

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 [Type] = KKK) [1] = = Array ([StaffID] [wage] =&G T      [Name] + king [Work] = LLL [Type] = TTT) [2] = = Array ([StaffID] + 70 [Wage] = [Name] + quit [Work] = QQQ [Type] + xxx)) 

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.