Home > Backend Development > PHP Tutorial > php 数组转化

php 数组转化

WBOY
Release: 2016-06-06 20:16:55
Original
1363 people have browsed it

如何将数组

<code>array(6) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [2]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [3]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [4]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [5]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
}
</code>
Copy after login
Copy after login

转变成

<code>array(3) {
  [0]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
    [1]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
  }
  [1]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
    [1]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
  }
  [2]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
    [1]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
  }
}

</code>
Copy after login
Copy after login

大概就是改成这样,将一个二维数组变成三位数组,每两个一组,最后还剩一个的话就单独一组。那二维数组的键值不一定是按顺序排的(如:0,1,2,3)。
还有个小问题,var_dump()有时候输出的是格式化的数组,但有时候输出的效果跟print_r()的效果一样,是什么情况?

回复内容:

如何将数组

<code>array(6) {
  [0]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [1]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [2]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [3]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [4]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
  [5]=>
  array(2) {
    [0]=>
    string(1) "1"
    [1]=>
    string(4) "qwer"
  }
}
</code>
Copy after login
Copy after login

转变成

<code>array(3) {
  [0]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
    [1]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
  }
  [1]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
    [1]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
  }
  [2]=>
  array(2) {
    [0]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
    [1]=>
    array(2) {
      [0]=>
      string(1) "1"
      [1]=>
      string(4) "qwer"
    }
  }
}

</code>
Copy after login
Copy after login

大概就是改成这样,将一个二维数组变成三位数组,每两个一组,最后还剩一个的话就单独一组。那二维数组的键值不一定是按顺序排的(如:0,1,2,3)。
还有个小问题,var_dump()有时候输出的是格式化的数组,但有时候输出的效果跟print_r()的效果一样,是什么情况?

array_chunk ?

切片 重组

发个print_r的版本吧,var_dump看着头疼

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