如何根據前序的順序比較兩個陣列?如果數組1是{1,2,3}並且數組2是{1,2,3},則顯示其他前綴。陣列2 {1,3,2}顯示錯誤..這是到目前爲止我的代碼..根據順序比較兩個陣列
foreach($questions as $question){
$question_answers = OrderingAnswer::where('question_id', $question->id)
->where('deleted',0)
->get()
->toArray();
$question_answer = $request->except('_token', 'test_id');
$answers = $question_answer[ $question->id];
foreach($question_answers as $answer){
if($answers === $question_answers){
echo "true";
}
else{
echo "false";
}
}
}
你的意思是你想基於鍵或索引進行比較嗎? –
你可以看看 - > https://stackoverflow.com/questions/5678959/php-check-if-two-arrays-are-equal – Maris
我有「id」=> 239,我有239這樣的順序, 240和我想要比較 – ylli