<?php
// 假设我们有一个名为Student的数据模型
class Student {
public $id;
public $name;
public $major;
public $grade;
public function __construct($id, $name, $major, $grade) {
$this->id = $id;
$this->name = $name;
$this->major = $major;
$this->grade = $grade;
}
public function getStudentInfo() {
return [
'ID' => $this->id,
'Name' => $this->name,
'Major' => $this->major,
'Grade' => $this->grade
];
}
}
// 数据中台系统示例代码
class DataPlatform {
private $students = [];
public function addStudent(Student $student) {
$this->students[$student->id] = $student;
}
public function getStudentInfoById($id) {
if (isset($this->students[$id])) {
return $this->students[$id]->getStudentInfo();
} else {
return "Student not found.";
}
}
public function getAllStudentInfo() {
$allStudentsInfo = [];
foreach ($this->students as $student) {
$allStudentsInfo[] = $student->getStudentInfo();
}
return $allStudentsInfo;
}
}
// 使用示例
$dataPlatform = new DataPlatform();
$student1 = new Student(1, "张三", "计算机科学", "大一");
$student2 = new Student(2, "李四", "软件工程", "大二");
$dataPlatform->addStudent($student1);
$dataPlatform->addStudent($student2);
print_r($dataPlatform->getAllStudentInfo());
?>