I have an array:
$quizzes = array();
$Quiz = array(
'quiz_id' => $quiz_id,
'correct' => $correctAnswers
);
$quizzes[] = $Quiz;
$quizzes
is an array which contains many quizzes called Quiz
, which in turn have $Quiz['quiz_id'] and $Quiz['correct']
. Now what I'm trying to do is to select a particular quiz from the list of quizzes in $quizzes
where quiz_id=1.
If such quiz exists, I would like to echo quiz is found. If no $Quiz with such id exists, echo no quiz is found.
A simple solution that I came up with is to do a foreach loop.
foreach($quizzes as $Quiz) if($Quiz['quiz_id'] == 1) {} else {}
However, since I have more than 1 quiz, it returns the else statement as many times as there are $Quiz['quiz_id'] != 1
which is many many times.