How do I change the subscript of an existing array?

Source: Internet
Author: User
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) "Never Say Goodbye"
}
[2]=>
Array (2) {
[0]=>
String (12) "201410090345"
[1]=>
String (4) "Girlfriends"
}

But the subscript is 0, 1, 2. Now I want to change the subscript to the content of the first column of this two-dimensional data.
For example, the subscript of the first line becomes 201410090343, the second line becomes 201410090344, and the third line becomes 201410090345.
How is this supposed to be done? Thank you


Reply to discussion (solution)

$a = Array ("  201410090343", "American Scam"), Array (  "201410090344", "no longer say break up"),  Array ("201410090345", "girlfriends"), ), foreach ($a as $v) $b [$v [0]] = $v; $a = $b; Var_dump ($a);
Array (3) {  ["201410090343"]=>  Array (2) {    [0]=>    string () "201410090343"    [1]=>    String (8) "American Scam"  }  ["201410090344"]=>  Array (2) {    [0]=>    string (12) "201410090344"    [1]=>    String (10) "No longer say break Up"  }  ["201410090345"]=>  Array (2) {    [0]=>    String ("201410090345"    [1]=>    string (4) "Girlfriends"  }

$list 1 = Array (
Array ("201410090343", "American Scam"), Array ("201410090344", "no longer say break up"), Array ("201410090345", "girlfriends"),

);
$list 2 = array ();
foreach ($list 1 as $key = = $val) {

$list 2[$val [0]] = $val;
}
Echo '

';
Print_r ($list 2);
?>
  • Related Article

    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.