I have the following array $students:
[
(int) 0 => [
'Students' => [
'number' => '1364249',
'first_name' => 'a',
'last_name' => 'asda',
'email' => '[email protected]'
],
'Responses' => [
'id' => '2'
]
]
]
There could me multiple students here. I have a variable before I get this array, which is a student number. I must then check this array to see if the student number exists anywhere. How would I do this? I tried the below but get an error 'Undefined index: number '.
$student_id = $this->Auth->user('Student.number');
$authorised = false;
foreach ($students as $student) {
if (isset($student['Students'])) {
if ($student['number'] == $student_id) {
$authorised = true;
}
}
}
I'm not good at PHP so I apologise if this is really obvious, I suspect I'm just doing the loop through the array very wrong, would appreciate any guidance.