Php 如何将实例添加到为某些单词排序的数组中

Php 如何将实例添加到为某些单词排序的数组中,php,arrays,Php,Arrays,我的代码有问题。 我想按数组中实例中的一些单词进行排序,然后重新替换到新数组中。 我做了一个小程序来做这个。 但不知怎么的,它不起作用。只有空的我能看见 -节目 --data.php -index.php <?php class Hoge { private $name; private $genre; public function __contstruct($name, $genre) { $this->name = $name; $this-&g

我的代码有问题。 我想按数组中实例中的一些单词进行排序,然后重新替换到新数组中。 我做了一个小程序来做这个。 但不知怎么的,它不起作用。只有空的我能看见

-节目 --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');
<?php foreach ($webs as $web): ?>
<p><?php echo $web->getName() ?></p>
<p><?php echo $web->getGenre() ?></p>
<?php endforeach ?>
谢谢你的帮助

public function __contstruct
这里的打字错误,应该是

public function __construct
这里的打字错误,应该是

public function __construct

您的目标输出是什么?
\uu contstruct
!=<代码>\构造(使用最后一个)。所以,投票结束是离题的,因为这是一个打字错误!目标在网站上。您的目标输出是什么?
\uu contstruct
!=<代码>\构造(使用最后一个)。所以,投票结束是离题的,因为这是一个打字错误!目标在网站上。