누군가 내가 왜 그랬는지 설명해 주시겠습니까? print_r($student->getStudents())
배열의 크기 만 가져오고 is_array
은 false를 반환합니다.정의 된 배열이 false를 반환하는 이유는 무엇입니까?
이 그것이 바로 당신이 그것을 전달하는 배열을 수정하고 배열의 새 길이를 반환, 새로운 배열을 반환하지 않습니다 내 출력
Jane Doe enrolled at Aviation High School
All students:
Nope!3
<?php
class Student{
public $name;
public $students = array('Jason', 'Joe');
public function __construct($name){
$this->name = $name;
$this->students = array_push($this->students, $name);
}
public function lastName(){
return "Doe";
}
public function getStudents(){
return $this->students;
}
}
class School{
public $name;
public function __construct($name){
$this->name = $name;
}
}
class Admin{
public function enroll(Student $student,School $school){
echo $student->name.' '.$student->lastName().' enrolled at '. $school->name;
echo '<br />All students:<br />';
echo is_array($student->getStudents()) ? 'Yeah!':'Nope!' ;
}
}
$student = new Student("Jane");
$school = new School("Aviation High School");
$admin = new Admin();
$admin->enroll($student, $school);
[array_push (http://php.net/manual/en/function.array-push.php) 내가 말할 것입니다 당신이 그것을 사용하는 방법을 작동하지 않습니다. – cheesemacfly