How can I change the subscript of an existing array?

Source: Internet
Author: User
How can I change the subscript of an existing array? There is such a two-dimensional array
[0] =>
Array (2 ){
[0] =>
String (12) 201410090343"
[1] =>
String (8) "American Scam"
}
[1] =>
Array (2 ){
[0] =>
String (12) 201410090344"
[1] =>
String (10) "do not say break up"
}
[2] =>
Array (2 ){
[0] =>
String (12) 201410090345"
[1] =>
String (4) "girlfriends"
}

The subscript is 0, 1, and 2. Now I want to change the subscript to the first column of the two-dimensional data.
For example, the subscript of the first row is 201410090343, the subscript of the second row is 201410090344, and the subscript of the third row is 201410090345.
What should I do? Thank you.


Reply to discussion (solution)

$ A = array ("201410090343", "American scam"), array ("201410090344", "do not say break up"), array ("201410090345 ", "Girlfriends"),); foreach ($ a as $ v) $ B [$ v [0] = $ v; $ a = $ B; var_dump ($ );
Array (3) {["201410090343"] => array (2) {[0] => string (12) "201410090343" [1] => string (8) "U.S. scam"} ["201410090344"] => array (2) {[0] => string (12) "201410090344" [1] => string (10) "Do not say breaking up"} ["201410090345"] => array (2) {[0] => string (12) "201410090345" [1] => string (4) "Girlfriends "}}

$ List1 = array (
Array ("201410090343", "American scam"), array ("201410090344", "do not say break up"), array ("201410090345", "Girlfriends "),

);
$ List2 = array ();
Foreach ($ list1 as $ key => $ val ){

$ List2 [$ val [0] = $ val;
}
Echo'

'; 

Print_r ($ list2 );
?>

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.