如何将实例添加到Array中,以分类一些单词



我的代码遇到了麻烦。我想用一些单词从数组中进行排序,然后将其重新化为新数组。我几乎没有计划这样做。但是某种程度上不起作用。我只能看到空。

- 程序-data.php

-index.php

<?php
class Hoge {
  private $name;
  private $genre;
  public function __contstruct($name, $genre) {
    $this->name = $name;
    $this->genre = $genre;
  }
  public function getName() {
    return $this->name;
  }

  public function getGenre() {
    return $this->genre;
  }
  public static function sortGenre($ary, $what) {
    $arrays = [];
    foreach($ary as $a){
        if ($a->getGenre() == "web") {
            $arrays[] = $a;
        }
    }
    return $arrays;
  }
}

$web1 = new Hoge ('name1','web');
$web2 = new Hoge ('name2','web');
$web3 = new Hoge ('name3','movie');
$web4 = new Hoge ('name4','out');
$web5 = new Hoge ('name5','web');
$web6 = new Hoge ('name6','some');
$web7 = new Hoge ('name7','yammy');
$ary = array($web1,$web2,$web3,$web4,$web5,$web6,$web7);
$webs = Hoge::sortGenre($ary,'web');

在index.php

<?php foreach ($webs as $web): ?>
<p><?php echo $web->getName() ?></p>
<p><?php echo $web->getGenre() ?></p>
<?php endforeach ?>

这是由

带来的
nothing shows

谢谢您的帮助。

public function __contstruct

错字应该是

public function __construct

最新更新