如何改变已存在的数组的下标啊?

WBOY
Release: 2016-06-23 13:47:57
Original
957 people have browsed it

有这样一个二维数组
 [0]=>
  array(2) {
    [0]=>
    string(12) "201410090343"
    [1]=>
    string(8) "美国骗局"
  }
  [1]=>
  array(2) {
    [0]=>
    string(12) "201410090344"
    [1]=>
    string(10) "不再说分手"
  }
  [2]=>
  array(2) {
    [0]=>
    string(12) "201410090345"
    [1]=>
    string(4) "闺蜜"
  }

但下标是0, 1, 2。现在想把下标改成这个二维数据的第一列的内容。
比如第一行的下标变成201410090343,第二行的变成201410090344,第三行的变成201410090345
这个应该如何做哪?谢谢


回复讨论(解决方案)

$a = array(  array("201410090343", "美国骗局"),  array("201410090344", "不再说分手"),  array("201410090345", "闺蜜"),);foreach($a as $v) $b[$v[0]] = $v;$a = $b;var_dump($a);
Copy after login
array(3) {  ["201410090343"]=>  array(2) {    [0]=>    string(12) "201410090343"    [1]=>    string(8) "美国骗局"  }  ["201410090344"]=>  array(2) {    [0]=>    string(12) "201410090344"    [1]=>    string(10) "不再说分手"  }  ["201410090345"]=>  array(2) {    [0]=>    string(12) "201410090345"    [1]=>    string(4) "闺蜜"  }}
Copy after login

$list1 = array(
array("201410090343","美国骗局"),array("201410090344","不再说分手"),array("201410090345","闺蜜"),

);
$list2 = array();
foreach($list1 as $key=>$val){

$list2[$val[0]] = $val;
}
echo '

Copy after login
';
print_r($list2);
?>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!