如何在单个 foreach 中使用两个数组

$created= [整数值] $data = [整数和字符串值]


这是我的代码:


@foreach($data as $arraydata)

                    @foreach($created as $create)

                 <tr>

                    <td data-label="Column 1">{{$i}}</td>

                    <td data-label="Column 2">{{$arraydata['start']}}</td>

                    <td data-label="Column 3">{{$arraydata['finish']}}</td>

                    <td data-label="Column 4">{{$arraydata['rate']}}</td>

                    <td data-label="Column 5">{{$arraydata['subject']['subject']}}</td>

                    <td data-label="Column 6">{{$arraydata['total_session']}}</td>

                    <td data-label="Column 7">{{$arraydata['amount']}}</td>

                    <td data-label="Column 7">{{$create['created_at']}}</td>

                 </tr>

                    @php

                        $i++

                    @endphp

                @endforeach

                @endforeach

我如何在单个 foreach 循环中使用


繁花如伊
浏览 148回答 2
2回答

人到中年有点甜

尝试这个@foreach($data as $index=>$arraydata)<tr>&nbsp; &nbsp; <td data-label="Column 1">{{++$i}}</td>&nbsp; &nbsp; <td data-label="Column 2">{{$arraydata['start']}}</td>&nbsp; &nbsp; <td data-label="Column 3">{{$arraydata['finish']}}</td>&nbsp; &nbsp; <td data-label="Column 4">{{$arraydata['rate']}}</td>&nbsp; &nbsp; <td data-label="Column 5">{{$arraydata['subject']['subject']}}</td>&nbsp; &nbsp; <td data-label="Column 6">{{$arraydata['total_session']}}</td>&nbsp; &nbsp; <td data-label="Column 7">{{$arraydata['amount']}}</td>&nbsp; &nbsp; <td data-label="Column 7">{{$created[$index]['created_at']}}</td></tr>@endforeach

杨魅力

试试这个方法:public function showDetails($id) {&nbsp; &nbsp; &nbsp; &nbsp; $users = array();&nbsp; &nbsp; &nbsp; &nbsp; $profiles= Profile::where(['profile_id' => $id])->get();&nbsp; &nbsp; &nbsp; &nbsp; $managers = Manager::where(['manager_id' => $id])->get();&nbsp; &nbsp; &nbsp; &nbsp; foreach ($profiles as $profile) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $profile = array('email' => $profile->user->email, 'name' => $profile->user->firstname);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $users[] = $profile;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; foreach ($managers as $manager) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $manager = array('email' => $manager->email, 'name' => $manager->name);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; $users[] = $manager ;&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; return view('custom-view', compact('users'));&nbsp; &nbsp; }
打开App,查看更多内容
随时随地看视频慕课网APP