【发布时间】:2021-12-23 23:24:45
【问题描述】:
我的代码正在运行,但我不知道如何创建删除功能我尽力搜索了一些但它不适合此代码我仍在学习基础知识,我将非常感谢您的帮助,谢谢提前很多
<?php
$straw = [];
$index = 0;
class Fruit {
private $name;
private $color;
public function describe($name, $color) {
$this->name = $name;
$this->color = $color;
}
public function intro() {
echo "{$this->name}"."\n";
echo "{$this->color}"."\n";
}
}
// Strawberry is inherited from Fruit
class Strawberry extends Fruit {
public function getfruit() {
echo $this->intro();
}
public function assignfruit($name, $color){
$this->describe($name, $color);
}
public function deletePatient($index){
unset($this->intro[$index]);
}
}
$strawberry1 = new Strawberry();
$strawberry1->assignfruit("Strawberry", "red");
$straw[$index] = $strawberry1;
$index++;
$strawberry2 = new Strawberry();
$strawberry2->assignfruit("Strawberry", "red");
$straw[$index]= $strawberry2;
$index++;
$strawberry2->deletePatient(1);
foreach ($straw as $star){
echo $star->getfruit();
}
【问题讨论】:
-
删除输出
-
对不起,如果我的解释不够清楚,
标签: php function oop inheritance