array(9) {    [0]=>    string(3) "标题1"&"/>   array(9) {    [0]=>    string(3) "标题1"&">

Home  >  Article  >  Backend Development  >  总是搞不懂foreach如何这样遍历这样的数组

总是搞不懂foreach如何这样遍历这样的数组

WBOY
WBOYOriginal
2016-06-13 11:38:39747browse

总是搞不懂foreach怎么这样遍历这样的数组
例如有这样一个数组:
array(4) {
  ["title"]=>
  array(9) {
    [0]=>
    string(3) "标题1"
    [1]=>
    string(3) "标题2"
    [2]=>
    string(3) "标题3"
    [3]=>
    string(3) "标题4"
  }
  ["id"]=>
  array(9) {
    [0]=>
    string(1) "n1"
    [1]=>
    string(1) "n2"
    [2]=>
    string(1) "n3"
    [3]=>
    string(1) "n4"
  }
  ["pic"]=>
  array(9) {
    [0]=>
    string(4) "1.jpg"
    [1]=>
    string(4) "2.jpg"
    [2]=>
    string(4) "3.jpg"
    [3]=>
    string(4) "4.jpg"
  }
  ["price"]=>
  array(9) {
    [0]=>
    string(5) "85.00"
    [1]=>
    string(6) "155.00"
    [2]=>
    string(5) "49.00"
    [3]=>
    string(5) "75.00"
  }
  ....更多数组

}

我想把里面的数据这样遍历循环出来:



  • 总是搞不懂foreach如何这样遍历这样的数组
    标题1
    85.00




  • 总是搞不懂foreach如何这样遍历这样的数组
    标题2
    155.00




  • 总是搞不懂foreach如何这样遍历这样的数组
    标题3
    49.00




  • 总是搞不懂foreach如何这样遍历这样的数组
    标题4
    75.00




  • 里面应该怎么写的?
    foreach($arr as $key => $value)
    {
    foreach(里面不会写了)
    {
    echo '
  • ';
    echo '';
    echo '总是搞不懂foreach如何这样遍历这样的数组';
    echo $title;
    echo ''.$price.'';
    echo '';
    echo '
  • ';
    }
    }
    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