运行 ❯
获取您
自己
的 PHP 服务器
×
更改方向
更改主题,深色/浅色
转至 Spaces
<!DOCTYPE html> <html> <body> <?php // Interface definition interface Animal { public function makeSound(); } // Class definitions class Cat implements Animal { public function makeSound() { echo " Meow "; } } class Dog implements Animal { public function makeSound() { echo " Bark "; } } class Mouse implements Animal { public function makeSound() { echo " Squeak "; } } // Create a list of animals $cat = new Cat(); $dog = new Dog(); $mouse = new Mouse(); $animals = array($cat, $dog, $mouse); // Tell the animals to make a sound foreach($animals as $animal) { $animal->makeSound(); } ?> </body> </html>
喵 叫 嘎吱