Home > Backend Development > PHP Tutorial > 怎么改变已存在的数组的下标啊

怎么改变已存在的数组的下标啊

WBOY
Release: 2016-06-13 12:07:37
Original
1479 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(<br />  array("201410090343", "美国骗局"),<br />  array("201410090344", "不再说分手"),<br />  array("201410090345", "闺蜜"),<br />);<br />foreach($a as $v) $b[$v[0]] = $v;<br />$a = $b;<br />var_dump($a);<br />
Copy after login
array(3) {<br />  ["201410090343"]=><br />  array(2) {<br />    [0]=><br />    string(12) "201410090343"<br />    [1]=><br />    string(8) "美国骗局"<br />  }<br />  ["201410090344"]=><br />  array(2) {<br />    [0]=><br />    string(12) "201410090344"<br />    [1]=><br />    string(10) "不再说分手"<br />  }<br />  ["201410090345"]=><br />  array(2) {<br />    [0]=><br />    string(12) "201410090345"<br />    [1]=><br />    string(4) "闺蜜"<br />  }<br />}<br /><br />
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);
?>
Related labels:
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