dougan7523
2017-06-11 15:59
浏览 45
已采纳

如何在laravel刀片中循环多维数组

        array:3 [▼
                "name" => array:3 [▼
                              0 => "user2"
                              1 => "user3"
                              2 => "user4"
                                 ]
                "email" => array:3 [▼
                              0 => "user2@gmail.com"
                              1 => "user3@gmail.com"
                              2 => "user4@gmail.com"
                                  ]
                "phone_number" => array:3 [▼
                              0 => "90352065"
                              1 => "69856352"
                              2 => "903520658"
                                  ]
              ]

I'm getting above response from multiple text boxes now I need to loop in view, so How to loop above arrays in view??

how can I display above array values like in below format

       User2 details
             name  : user2
             email : user2@gmail.com
             phone_number : 90352065
       User3 details
             name  : user3
             email : user3@gmail.com
             phone_number : 69856352 
       User4 details
             name  : user4
             email : user4@gmail.com
             phone_number : 903520658

图片转代码服务由CSDN问答提供 功能建议

  array:3 [▼
“name”=> 数组:3 [▼
 0 =>  “user2”
 1 =>  “user3”
 2 =>  “user4”
] 
“email”=> 数组:3 [▼
 0 =>  “user2@gmail.com”
 1 =>  “user3@gmail.com”
 2 =>  “user4@gmail.com”
] 
“phone_number”=> 数组:3 [▼
 0 =>  “90352065”
 1 =>  “69856352”
 2 =>  “903520658”
] 
] 
   
 
 

我现在需要在多个文本框中获得响应,我需要在视图中循环,所以如何循环上面的数组 在视图??

如何显示上面的数组值,如下面的格式

  User2 details 
 name:user2 
 email  :user2@gmail.com 
 phone_number:90352065 
用户3详细信息
名称:user3 
电子邮件:user3@gmail.com 
 phone_number:69856352 
用户4详细信息
名称:user4 
电子邮件:user4 @ gmail  .com 
 phone_number:903520658 
   
 
  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongwen5336 2017-06-11 16:09
    已采纳

    I presume below is your array structure

    $original_array = [
      "name" => [
          "user2","user3","user4"
      ],
      "email" => [
          "user2@gmail.com","user3@gmail.com","user4@gmail.com"
      ],
      "phone_number" => [
        "90352065","69856352","903520658"
      ]
    ];
    

    now to get desired output you can use below code

    <dl>
    @foreach($original_array['name'] as $key => $name)
      <dt>{{ $name }} Details</dt>
      <dd>
        <ul>
          <li>Name: {{ $name }}</li>
          <li>Email: {{ $original_array['email'][$key] }}</li>
          <li>Phone Number: {{ $original_array['phone_number'][$key] }}</li>
        </ul>
      </dd>
    @endforeach
    </dl>
    
    点赞 评论
  • dsbowmvth16379079 2017-06-11 16:09

    kind of

    @foreach($nameArray as $index => $nameArrayElement)     
        <tr>
            <td>{{ $mainArray['name'][$index] }}</td>       
            <td>{{ $mainArray['email'][$index] }}</td>      
            <td>{{ $mainArray['phone_number'][$index] }}</td>   
        </tr> 
    @endforeach
    

    Take in mind that the number of names are equal to the number of rows

    点赞 评论

相关推荐 更多相似问题