Home  >  Article  >  Backend Development  >  如何改变已存在的数组的下标啊?

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

WBOY
WBOYOriginal
2016-06-23 13:47:57988browse

有这样一个二维数组
 [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);
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) "闺蜜"  }}

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

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

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

';  
print_r($list2);
?>
Statement:
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