Php Method for modifying the array key name, php array key name example

Source: Internet
Author: User

Php Method for modifying the array key name, php array key name example

This example describes how to modify the array key name in php. We will share this with you for your reference. The details are as follows:

$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);

The running result is:

Array(  [0] => Array    (      [StaffId] => 50      [Wage] => 60      [Name] => long      [Work] => zzz      [Type] => kkk    )  [1] => Array    (      [StaffId] => 60      [Wage] => 70      [Name] => king      [Work] => lll      [Type] => ttt    )  [2] => Array    (      [StaffId] => 70      [Wage] => 80      [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.