Change the default key of array to a specified string.

Source: Internet
Author: User
{Code...} I want to change it to this {code ...}
dump($array);
Array (2) {[0] => array (6) {[0] => string (1) "1" [1] => string (10) "1470650276" [2] => string (12) "tester" [3] => string (9) "vpn for sale" [4] => string (20) "10 monthly VPN for sale" [5] => string (6) "100000"} [1] => array (6) {[0] => string (1) "2" [1] => string (10) "1470650739" [2] => string (12) "tester" [3] => string (9) "server" [4] => string (28) "dual-core CPU 2G memory 40SDD hard drive" [5] => string (5) "15000 "}}

I want to change it to this

Array (2) {[0] => array (6) {["record_id"] => string (1) "1" ["record_create_time"] => string (10) "1470650276" ["record_create_people"] => string (12) "tester" ["record_name"] => string (9) "vpn for sale" ["record_comment"] => string (20) "10 monthly VPN for sale" ["record_money"] => string (6) "100000"} [1] => array (6) {["record_id"] => string (1) "2" ["record_create_time"] => string (10) "1470650739" ["record_create_people"] => string (12) "tester" ["record_name"] => string (9) "server" ["record_comment"] => string (28) "dual-core CPU 2 GB memory 40SDD hard disk" ["record_money"] => string (5) "15000 "}}

Reply content:
dump($array);
Array (2) {[0] => array (6) {[0] => string (1) "1" [1] => string (10) "1470650276" [2] => string (12) "tester" [3] => string (9) "vpn for sale" [4] => string (20) "10 monthly VPN for sale" [5] => string (6) "100000"} [1] => array (6) {[0] => string (1) "2" [1] => string (10) "1470650739" [2] => string (12) "tester" [3] => string (9) "server" [4] => string (28) "dual-core CPU 2G memory 40SDD hard drive" [5] => string (5) "15000 "}}

I want to change it to this

Array (2) {[0] => array (6) {["record_id"] => string (1) "1" ["record_create_time"] => string (10) "1470650276" ["record_create_people"] => string (12) "tester" ["record_name"] => string (9) "vpn for sale" ["record_comment"] => string (20) "10 monthly VPN for sale" ["record_money"] => string (6) "100000"} [1] => array (6) {["record_id"] => string (1) "2" ["record_create_time"] => string (10) "1470650739" ["record_create_people"] => string (12) "tester" ["record_name"] => string (9) "server" ["record_comment"] => string (28) "dual-core CPU 2 GB memory 40SDD hard disk" ["record_money"] => string (5) "15000 "}}

$keys = array('record_id', 'record_create_time', 'record_create_people', 'record_name', 'record_comment', 'record_money');foreach ($array as $i=>$vals) {    $array[$i] = array_combine($keys, $vals);}var_dump($array);

Let's take a look at the array operation functions in the manual.

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.