I want to show a specific data of an array, I have the following code and I am trying to print the printConcreteStudent
function to print a specific student that I indicate passed through the variable $name
.
When trying to find the student I get the following error:
Fatal error: Uncaught Error: Can not use object of type Student as array
The structure of the array is as follows:
array(1) {
[0]=>
object(Student)#1 (4) {
["name"]=>
string(5) "Student1"
["lastname":"Student":private]=>
string(7) "lastName1"
}
}
And the function with which I am trying to print a specific data :
function printConcreteStudent($name) {
foreach($this->students as $key=>$value){
if($value["name"] == $name){
echo $value->getName() . " ";
echo $value->getLastName() . " ";
}
}
}