【发布时间】:2018-06-11 12:59:13
【问题描述】:
我正在尝试制作测验应用程序。我有 600 多个不同类别的问题,如 jp、sn、ei 等。现在我想随机向用户显示不同类别的问题和选项。但是出现错误。有人会帮我做对吗。我试过这样的东西 - 在我的 Controller.php 中
public function index()
{
$jp = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'JP')->get();
$sn = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'SN')->get();
$ei = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'EI')->get();
$tf = DB::table('e_questions')->take(2)->inRandomOrder()->where('dichotomy', '=', 'TF')->get();
$equestions = array("$jp","$sn","$ei","$tf");
//dd($equestions);
return view('question.english.index', compact('equestions'));
}
在我看来 index.blade.php
@foreach($equestions as $equestion)
<p>{{ $equestion->question }}</p>
<p>{{ $equestion->option1 }}</p>
<p>{{ $equestion->option2 }}</p>
@endforeach
【问题讨论】:
-
我删除了这个。
-
试试这样 $equestions = array_merge($jp,$sn,$ei,$tf);并请显示您面临的错误。
标签: php arrays laravel multidimensional-array